Numerical Methods
Flow Chart of Bisection
Method
Start
= >
f(xl)f(xm):0
Define the
function <
xu = xm xl = xm
Read xl and xu
Ea =
|(xm-xmold)*100/xm|
>
f(xl)f(xu) : 0 Xmold=xm
< Print Count, xl,
Ea : ε (limit) <
Read ε(limit) & xu, xm , f(xl),
max_iteration > f(xm) f(xl)f(xm) &
Iteration_count++ error
iteration_count=0 Stop
xmold = xl
Iteration_count :
> No convergence
max_iteration
Find xm=(xl+xu)/2
<
2
Program (Matlab Code) for
Bisection method
% Bisection method for finding the root of a nonlinear equation
clc;
clear all;
f = @(x)(x^3 + 6 * x^2 - 7 * x - 60);
while 1
xl = input('Enter the value of xl: ');
xu = input('Enter the value of xu: ');
if (f(xl)*f(xu)<0)
disp('The xl and xu encompass atleast one root');
break;
end
disp ('The xl and xu do not encompass the root');
disp ('Enter a new set');
end
maxcount = input('Enter the value of maximum number of count: ');
eps = input('Enter the value of epsilon (%): ');
count=0;
xmold=xl;
disp( ' Count Xl Xu Xm f(Xl) f(Xm) fXl*fXm % Error ')
3
Program (Matlab Code) for
Bisection method (continued)
while count<maxcount if (f(xl)*f(xm)<0)
xm=(xl+xu)/2; xu=xm;
err=abs((xm- else
xmold)*100/xm); xl=xm;
xmold=xm; end
Y(1)=count; if
Y(2)=xl; (abs(f(xl)*f(xm))<1.0e-10)
Y(3)=xu; break
Y(4)=xm; end
Y(5)=f(xl); if err <= eps
Y(6)=f(xm); break;
Y(7)=Y(5)*Y(6); end
Y(8)=err; count=count+1;
disp (Y); end
if count == maxcount &&
err>eps 4
Find the root of the following
nonlinear equation
f(x) = x^3 – 4 * x ^2 – x + 4
xl=3.5 and xu = 4.8
RESULT
Iteration xm % Error f(xm)
1 4.1500 15.6627 2.4334
2 3.8250 8.4967 -2.3854
3 3.9875 4.0752 -0.1863
5
Find the root of the following
nonlinear equation
f(x)= 5 * exp ( -x) -2
Assume xl=0 and xu=2
Calculate xm, % error and f(xm) for
three iterations
Iteration Xm % Error f(xm)
1 1.0 100.0 -0.1606
2 0 .50 100.0 1.0327
3 0.75 33.33 0.3618
6
Idea about finding root in a
faster way
f x
Figure 1
f xU
Exact root
xL
O xr xU x
f xL
7
False position method
However, in the example shown in Figure 1, the
bisection method may not be efficient because it
does not take into consideration that f(xL) is much
closer to the zero of the function f(x) as compared to
f(xU)
In other words, the next predicted root xr would be
closer to xL (in the example as shown in Figure 1),
than the mid-point between xL and xU
The false-position method takes advantage of this
observation mathematically by drawing a secant from
the function value at xL to the function value at xU
and estimates the root as where it crosses the x-axis.
8
False-Position Method
(continued)
Based on two similar triangles, shown in figure 1,
one gets 0 f ( xL ) 0 f ( xU )
xr x L xr xU
(4)
From equation(4),
xr xL f xU xr xU f xL
one obtains
xU f xL xL f xU xr f xL f xU
The above equation xU f xbe
can L solved
xL f xU to obtain the
xr
next predicted root xr asf xL f xU
(5) 9
False-Position Method
(continued)
The equation (5), through simple algebraic
manipulations, can also be expressed as
f xU
xr xU
f xU f xL
(6)
xU x L
or f xL
xr x L
f xL f xU
x L x U
(7)
.
10
Algorithm for False-Position
method
The steps to apply the false-position method to find the root of the
equation f(x)=0 are as follows.
Step#1: Choose xL and xU as two guesses for the root such that
f xL f xU 0
or in other words f(x) changes sign betn xL
and xU
xU f xL xL f xU
xr
Step#2: Estimate the root xr of the equation f(x)=0 as
f xL f xU
f xLNow
Step #3. f xr check
0 the following
If f xL f xr 0 then the root lies between xL and xr
If f xL f xr 0 then the root lies between x U and xr
If then the root is x r. Stop the algorithm.
11
Algorithm for False-Position
method (continued)
Step #4: Find the new estimate of the root
xU f xL xL f xU
xr
f xL f xU
Find the absolute relative approximate error as
xrnew xrold
a new
100
where xr
xrnew= estimated root from present iteration
xrold= estimated root from previous
iteration
12
Algorithm for False-Position
method (continued)
Step # 5. Compare the absolute relative approximate
error with the pre-specified relative error tolerance .
If a then
s 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.
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 and #4!
13
xfUrL1a3x.%
m
1944
1320
1313 10755
10
Example 1: Floating ball
problem
Table 1 Root of floating ball problem for false-position
method
Iteration xL xU xr a % f(xm)
1 0.0000 0.1100 0.0660 ---- 3.1944X10-5
2 0.0000 0.0660 0.0611 8.00 1.1320X10-5
3 0.0611 0.0660 0.0624 2.05 1.1313X10-7
14
xfUrLa x%
L
U
m
Example 2
f x x 4 xusing
2 0 the initial guesses of
2
Find the root of
xL=-2.5 and xU=-1.0 and a pre-specified tolerance s 0.1of
%
Table 2 Rootf of
x x 4 x for
2 false-position
2
0 method
Iteration xL xU f(xL) f(xU) xr a % f(xr)
1 -2.5 -1 -21.13 25.00 -1.813 N/A 6.319
2 -2.5 -1.813 -21.13 6.319 -1.971 8.024 1.028
3 -2.5 -1.971 -21.13 1.028 -1.996 1.229 0.1542
4 -2.5 -1.996 -21.13 0.1542 -1.999 0.1828 0.02286
5 -2.5 -1.999 -21.13 0.02286 -2.000 0.02706 0.003383
15
Flow Chart of False Position
Method
Start
= f(xl)f(xi):0 >
Define the
function <
xu = xi xl = xi
Read xl and xu
Ea = |(xi-xiold)*100/xi|
A
f(xl)f(xu) : 0 > Xiold=xi
<
Read Elimit & Ea : Elimit < Print Count, xi
& f(xi)
max_iteration >
iteration_count= Iteration_count++ Stop
0
xiold = xl Iteration_count :
xi = [xuf(xl)-xlf(xu]/ max_iteration > No convergence
[f(xl)-f(xu)] < 16
The program for False
Position method in Matlab
while count < maxcount
clear all; xi=(xu*f(xl) –xl*f(xu))/
f = @ (x) (x^2 - 5*x + 6); (fxl)-f(xu)) ;
while 1 if (f(xl)*f(xi) < 0)
xl = input('Enter the value of xl: '); xu = xi;
else
xu = input('Enter the value of xu: '); xl = xi;
if (f(xl)*f(xu) < 0) end
disp('The xl and xu encompass atleast err=abs(xi - xiold)*100/xi);
one root'); xmold = xi;
Y(1) = count;
break; Y(2) = xi;
end Y(3) = err;
disp ('The xl and xu do not encompass Y(4)=f(xi);
the root’); disp (Y);
if (abs(f(xl)*f(xi))<1.0e-10)
disp(‘Enter a new set'); break;
end end
maxcount = input('Enter the value of if err < eps
maximum break;
end
number of count: '); count = count+1;
eps = input('Enter the value of epsilon (%): '); end
count = 0; if count == maxcount && err>eps
xiold = xl; disp ('no convergence');
17
end
Thanks
18