What is the Bisect Function and How Does it Work?

  • Thread starter Thread starter jdawg
  • Start date Start date
  • Tags Tags
    Function
Click For Summary
SUMMARY

The Bisect Function is a MATLAB implementation designed to find the root of a function using the bisection method. The function signature is function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin), where func is the target function, xl and xu are the lower and upper guesses, es is the desired relative error, and maxit is the maximum number of iterations. The function checks for a sign change between func(xl) and func(xu) to ensure a root exists within the interval. It iteratively narrows the interval until the desired accuracy is achieved or the maximum iterations are reached.

PREREQUISITES
  • Understanding of the bisection method in numerical analysis
  • Familiarity with MATLAB programming and function syntax
  • Basic knowledge of error analysis and convergence criteria
  • Ability to define and use functions in MATLAB
NEXT STEPS
  • Explore MATLAB's built-in functions for root-finding, such as fzero
  • Learn about error handling in MATLAB to improve robustness of functions
  • Study the convergence properties of the bisection method compared to other root-finding methods
  • Implement additional root-finding algorithms, such as Newton-Raphson and Secant methods
USEFUL FOR

Students, educators, and professionals in engineering, mathematics, and computer science who are interested in numerical methods for solving equations and optimizing MATLAB code.

jdawg
Messages
366
Reaction score
2

Homework Statement


I'm not really sure how to define my bisect function.. I included my work and question in the images attached.

Homework Equations

The Attempt at a Solution

 

Attachments

  • pitch.png
    pitch.png
    53 KB · Views: 517
  • w2.png
    w2.png
    9.2 KB · Views: 480
Last edited:
Physics news on Phys.org
I guess I was thinking it was a built in function in matlab, I've tried to look at a few examples of bisection codes and I'm not super sure how to format it to make it work with this problem.
 
function [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,varargin)
% bisect: root location zeroes
% [root,fx,ea,iter]=bisect(func,xl,xu,es,maxit,p1,p2,...):
% uses bisection method to find the root of func
% input:
% func = name of function
% xl, xu = lower and upper guesses
% es = desired relative error (default = 0.0001%)
% maxit = maximum allowable iterations (default = 50)
% p1,p2,... = additional parameters used by func
% output:
% root = real root
% fx = function value at root
% ea = approximate relative error (%)
% iter = number of iterations
if nargin<3,error('at least 3 input arguments required'),end
test = func(xl,varargin{:})*func(xu,varargin{:});
if test>0,error('no sign change'),end
if nargin<4|isempty(es), es=0.0001;end
if nargin<5|isempty(maxit), maxit=50;end
iter = 0; xr = xl; ea = 100;
while (1)
xrold = xr;
xr = (xl + xu)/2;
iter = iter + 1;
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl,varargin{:})*func(xr,varargin{:});
if test < 0
xu = xr;
elseif test > 0
xl = xr;
else
ea = 0;
end
if ea <= es | iter >= maxit,break,end
end
root = xr; fx = func(xr, varargin{:});
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
2K
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K