0% found this document useful (0 votes)
2 views1 page

Bisection Method for Root Finding

This document outlines a program that implements the bisection method to compute the root of a nonlinear equation. It defines the function, sets the range and stopping criteria, and includes a loop for iterations to find the root while checking for convergence. If the root cannot be found within the specified range, it notifies the user accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Bisection Method for Root Finding

This document outlines a program that implements the bisection method to compute the root of a nonlinear equation. It defines the function, sets the range and stopping criteria, and includes a loop for iterations to find the root while checking for convergence. If the root cannot be found within the specified range, it notifies the user accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

% Program Bisect

Step-wise algorithm
% Program for computing root of nonlinear
% equation by using the bisection method.
% Define the following given values:
% xl = left value of the root x
% xr = right value of the root x
% es = stopping criterion tolerance (%)
% Define the function of the problem:
func = @(x)(exp(-x/4)*(2-x) - 1);
% Assign range and stopping tolerance:
xl = 0.; xr = 2.; es = 0.001;
% Check whether root is in given range:
fxl = func(xl); fxr = func(xr);
aa = fxl*fxr;
while aa >= 0.
disp(' Root is not in the given range');
break
end
fprintf('\n Iteration No. x \n');
for iter = 1:500
xm = (xl+xr)/2.; fxm = func(xm);
fxr = func(xr); aa = fxm*fxr;
if aa > 0.
% Case A: xl < root < xm
xr = xm;
else
% Case B: xm < root < xr
xl = xm;
end
% Check for the tolerance:
xn = (xl+xr)/2.;
fprintf(' %8d %22.6e\n', iter, xn);
tol = abs((xn-xm)*100./xn);
if tol < es
fprintf('\n The root is %14.6e\n', xn)
break
end
end
while tol > es
fprintf(' Root cannot be reached for\n');
fprintf(' the given range');
break
end

You might also like