Download presentation
Presentation is loading. Please wait.
1
Numerical Methods Slide Credit
Lecture 3 Finding Roots of Nonlinear Equations: Revision of Bisection Method & False Position Method Slide Credit Dr. S. M. Lutful Kabir
2
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, xu, xm , f(xl), f(xm) f(xl)f(xm) & error < Read ε(limit) & max_iteration Ea : ε (limit) > Iteration_count++ Stop iteration_count=0 xmold = xl Iteration_count : max_iteration No convergence > Find xm=(xl+xu)/2 <
3
Program (Matlab Code) for Bisection method
% Bisection method for finding the root of a nonlinear equation clc; clear all; f + 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'); 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 ')
4
Program (Matlab Code) for Bisection method (continued)
if (f(xl)*f(xm)<0) xu=xm; else xl=xm; end if (abs(f(xl)*f(xm))<1.0e-10) break if err <= eps break; count=count+1; if count == maxcount && err>eps disp ('no convergence'); while count<maxcount xm=(xl+xu)/2; err=abs((xm-xmold)*100/xm); xmold=xm; Y(1)=count; Y(2)=xl; Y(3)=xu; Y(4)=xm; Y(5)=f(xl); Y(6)=f(xm); Y(7)=Y(5)*Y(6); Y(8)=err; disp (Y);
5
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)
6
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)
7
Idea about finding root in a faster way
Figure 1
8
False position method In Figure 1, the bisection method does not take into consideration that f(xL) is much closer to zero compared to f(xU) In other words, the next predicted root xr would be closer to xL than the mid-point of 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 by where it crosses the x-axis.
9
False-Position Method (continued)
Based on two similar triangles, shown in figure 1, one gets (4) From equation (4), one obtains The above equation can be solved to obtain the next predicted root xr as (5)
10
False-Position Method (continued)
The equation (5), through simple algebraic manipulations, can also be expressed as (6) or (7) .
11
Algorithm for False-Position method
The steps for 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 or in other words f(x) changes sign between xL and xU Step#2: Estimate the root xr of the equation f(x)=0 as Step #3. Now check the following If then the root lies between xL and xr If then the root lies between xU and xr If then the root is xr. Stop the algorithm.
12
Algorithm for False-Position method (continued)
Step #4: Find the new estimate of the root Find the absolute relative approximate error as where xrnew= estimated root from present iteration xrold= estimated root from previous iteration
13
Algorithm for False-Position method (continued)
Step # 5. Compare the absolute relative approximate error with the pre-specified relative error tolerance . If then go to step 3, else stop the algorithm. Note that one should also check whether number of iterations has exceeded the maximum number allowed. If so, one needs to terminate the algorithm and notify the user. 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!
14
Example 1: Floating ball problem
Table 1 Root of floating ball problem for false-position method Iteration xL xU xr f(xm) 1 0.0000 0.1100 0.0660 ---- 3.1944X10-5 2 0.0611 8.00 1.1320X10-5 3 0.0624 2.05 1.1313X10-7
15
Table 2 Root of for false-position method
Example 2 Find the root of using the initial guesses of xL=-2.5 and xU=-1.0 and a pre-specified tolerance of Table 2 Root of for false-position method Iteration xL xU f(xL) f(xU) xr f(xr) 1 -2.5 -1 -21.13 25.00 -1.813 N/A 6.319 2 -1.971 8.024 1.028 3 -1.996 1.229 0.1542 4 -1.999 0.1828 5 -2.000
16
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 < < Print Count, xi & f(xi) Ea : Elimit Read Elimit & max_iteration > Iteration_count++ iteration_count=0 xiold = xl Stop Iteration_count : max_iteration No convergence xi = [xuf(xl)-xlf(xu]/ [f(xl)-f(xu)] > <
17
The program for False Position method in Matlab
while count < maxcount xi=(xu*f(xl) –xl*f(xu))/ (fxl)-f(xu)) ; if (f(xl)*f(xi) < 0) xu = xi; else xl = xi; end err=abs(xi - xiold)*100/xi); xmold = xi; Y(1) = count; Y(2) = xi; Y(3) = err; Y(4)=f(xi); disp (Y); if (abs(f(xl)*f(xi))<1.0e-10) break; if err < eps count = count+1; if count == maxcount && err>eps disp ('no convergence'); clear all; f (x) (x^2 - 5*x + 6); 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'); maxcount = input('Enter the value of maximum number of count: '); eps = input('Enter the value of epsilon (%): '); count = 0; xiold = xl; disp( ' Count Xi Error f(xi)');
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.