You are on page 1of 5

Islamic University of Technology (IUT)

Organization of Islamic Cooperation (OIC)


Department of Electrical and Electronic Engineering (EEE)

Course No. : Math 4522


Course Name : Numerical Methods Lab.
Experiment No. : 02
Experiment Name : Introduction to bisection method and false-position method.

 Objective:

To get familiarized with the bisection method and false-position method to find the root of the non-
linear equation.

 Theory:
o Bisection method algorithm
The steps to apply the bisection method to find the root of the equation f ( x)  0 are

1. Choose x and xu as two guesses for the root such that f ( x ) f ( xu )  0 , or in other
words, f (x) changes sign between x and xu .
2. Estimate the root, xr , of the equation f ( x)  0 as the mid-point between x and xu
as
x   xu
xr =
2

3. Now check the following


a) If f ( x ) f ( x r )  0 , then the root lies between x and x r ; then x  x and
xu  x r .
b) If f ( x ) f ( x r )  0 , then the root lies between x r and xu ; then x   x r and
xu  xu .
c) If f ( x ) f ( x r )  0 ; then the root is x r . Stop the algorithm if this is true.
4. Find the new estimate of the root
x   xu
xr =
2

5. Find the absolute relative approximate error as

xrnew - xrold
a =  100
xrnew

Where, x rnew = estimated root from present iteration, and

x rold = estimated root from previous iteration


6. Compare the absolute relative approximate error a with the pre-specified relative
error tolerance s . If a s , then go to Step 3, else stop the algorithm. Note one
should also check whether the number of iterations is more than the maximum number
of iterations allowed. If so, one needs to terminate the algorithm and notify the user
about it.

o False-Position Algorithm

The steps to apply the false-position method to find the root of the equation f x   0 are as
follows.

1. Choose xL and xU as two guesses for the root such that f x L  f xU   0 , or in other
words, f  x  changes sign between xL and xU .
2. Estimate the root, xr of the equation f x   0 as

xU f  x L   x L f xU 
xr 
f  x L   f xU 

3. Now check the following


a. If f x L  f xr   0 , then the root lies between xL and xr ; then x L  x L
and xU  x r .
b. If f x L  f xr   0 , then the root lies between xr and xU ; then x L  xr
and xU  xU .
c. If f x L  f xr   0 , then the root is x r . Stop the algorithm.
4. Find the new estimate of the root

xU f  x L   x L f xU 
xr 
f  x L   f xU 

5. Find the absolute relative approximate error as

xrnew  xrold
a   100
xrnew

Where,

x rnew = estimated root from present iteration, and

x rold = estimated root from previous iteration


6. Compare the absolute relative approximate error a with the pre-specified relative
error tolerance s . If a s , then go to step 3, else stop the algorithm. Note one
should also check whether the number of iterations is more than the maximum
number of iterations allowed. If so, one needs to terminate the algorithm and notify
the user about it.

Please note that the false-position and bisection algorithms are quite similar. The only
difference is the formula used to calculate the new estimate of the root 𝑥𝑟 as shown in
steps 2.

 Demonstration:

The equation for calculating the drag coefficient for a para jumper is:
𝑔𝑚 𝑐
−( )∗𝑡
𝑓(𝑐) = (1 − 𝑒 𝑚 ) − 𝑣
𝑐

Here, c is the variable for drag coefficient, g is the acceleration due to gravity, m is the mass of the
person, v is the velocity, and t is the time before free falling.

Now, using m=68.1 kg, g=9.81m/s2, v=40 m/s and t=10 s, a code is demonstrated to calculate drag
coefficient c using bisection method.

clc
clear all
close all
%% INPUTS: Enter the following
% number of terms to calculate
n=5;
% Function in f(c)=0
f = inline('(9.81*68.1/c)*(1-exp(-(c/68.1)*10))-40');
% Upper initial guess same as example 5.2 of the book
xu = 16;
% Lower initial guess same as example 5.2 of the book
xl = 12;
% Lower bound of range of 'x' to be seen in the graph
lxrange =10;
% Upper bound of range of 'x' to be seen in the graph
uxrange = 18;
%
% The following finds the upper and lower 'y' limits for the plot based on
the given
% 'x' range in the input section.
uyrange = f(lxrange);
lyrange = f(lxrange);
for i=lxrange:(uxrange-lxrange)/10:uxrange
if f(i) > uyrange
uyrange = f(i);
end
if f(i) < lyrange
lyrange = f(i);
end
end
%% This graphs the function and two lines representing the two initial
guesses
figure(1)
fplot(f,[lxrange,uxrange])
hold on
plot([xl,xl],[uyrange,lyrange],'y','linewidth',2)
plot([xu,xu],[uyrange,lyrange],'g','linewidth',2)
plot([lxrange,uxrange],[0,0],'k','linewidth',1)
title('Entered function on given interval with initial guesses')
hold off
%% -------------------------------------------------------------------------
-------
for i=1:1:n
figure(i+1)
xr=(xu+xl)/2;
% This graphs the function and two lines representing the two guesses
subplot(3,1,2),fplot(f,[lxrange,uxrange])
hold on
plot([xl,xl],[uyrange,lyrange],'y','linewidth',2)
plot([xu,xu],[uyrange,lyrange],'g','linewidth',2)
plot([xr,xr],[uyrange,lyrange],'r','linewidth',2)
plot([lxrange,uxrange],[0,0],'k','linewidth',1)
title('Entered function on given interval with upper and lower guesses')
hold off
% This portion adds the text and math to the top part
subplot(3,1,1), text(0,1,[sprintf('Iteration %d',i)])
text(0.2,.8,['xr = (xu + xl) / 2 = ',num2str(xr)])
text(0,.6,['Finding the value of the function at the lower and upper guesses
and the estimated root'])
text(0.2,.4,['f(xl) = ',num2str(f(xl))])
text(0.2,.2,['f(xu) = ',num2str(f(xu))])
text(0.2,0,['f(xr) = ',num2str(f(xr))])
axis off
% Check the interval between which the root lies
if f(xl)*f(xr)<0
xu=xr;
else
xl=xr;
end
% Calculate relative approximate error
if i>1
ea=abs((xr-xp)/xr)*100;
else
end
% This portion adds the text and math to the bottom
subplot(3,1,3)
if i>1
text(0,1,['Absolute relative approximate error'])
text(0,.8,['ea = abs((xr - xp) / xr)*100 = ',num2str(ea),'%'])
else
end
text(0,.4,['Check the interval between which the root lies. Does it lie in (
xl , xu ) or ( xr , xu )?'])
text(0.2,0.2,['xu = ',num2str(xu)])
text(0.2,0,['xl = ',num2str(xl)])
axis off
xp=xr;
end

 Verification:

Now verify our calculation using the example 5.3 from the text book Steven C. Chapra.

 Task in the Lab

o Write a code to calculate drag coefficient c using false position method and comment which
method is better (lower value for the absolute relative approximation error makes a method
better).

o Write another code to calculate the number of terms required for an absolute relative
approximate error lower than 0.05%

 Task for the Lab Report

o Write the code to locate the root of 𝑓(𝑥) = 𝑥10 − 1 using bisection and false position with
initial gauss x = 0 and 1.3 and comment which method is better (lower value for the
absolute relative approximation error makes a method better).
o Find the smallest positive root of the function (x is in radians) 𝑥 2 |𝑐𝑜𝑠√𝑥| = 5 using the
false-position and bisection method. To locate the region in which the root lies, first plot
this function for values of x between 0 and 5. Perform the computation until εa falls below
εs = 1%.

You might also like