0% found this document useful (0 votes)
62 views20 pages

Lecture 3 - Solving Non-Linear Equations (BiSection) 1

Uploaded by

mahmoudtaha6548
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)
62 views20 pages

Lecture 3 - Solving Non-Linear Equations (BiSection) 1

Uploaded by

mahmoudtaha6548
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
You are on page 1/ 20

Solving Non-Linear Equation

Bisection Method
Prof. Osama Abdel Raouf
Roots of Equation
• Equation : 𝑓 𝑥 = 𝑎𝑥 2 + 𝑏𝑥 + 𝑐
• Roots of equation represent the values of x that make 𝑓 𝑥 =0 ➔
also called the zeros of the equation
• Analytical Method-> Exact solutions:
• The handy Quadratic formula for solving 𝑓 𝑥 is :
−𝑏± 𝑏2 −4𝑎𝑐
• X= 2𝑎

• There are many other functions for which the root cannot
be determined so easily ➔ numerical methods
• Ex: 𝑓 𝑥 = 𝑒 𝑥 − 𝑥

a= input('a=');
b= input('b=');
c= input('c=');
%Analytical (Exact solution)
x1=-b+sqrt(b^2-4*a*c)/(2*a)
x2=-b-sqrt(b^2-4*a*c)/(2*a)
Roots of Equation
• Equation : 𝑓 𝑥 = 𝑎𝑥 2 + 𝑏𝑥 + 𝑐
• Roots of equation represent the values of x that make 𝑓 𝑥 =0 ➔
also called the zeros of the equation
• Numerical Method-> approximation solutions:

Graphical techniques MATLAB


• Plot the function and determine a= input('a=');
where it crosses the x axis.
• This point, which represents the x b= input('b=');
value for which 𝑓 𝑥 =0 , is the root. c= input('c=');
• Although graphical methods are
useful for obtaining rough estimates %Graphically (app. solution)
of roots, they are limited because of
their lack of precision. X=linspace(1,10,100);
• However, these estimates can be Y=5x.^2+3x-4
employed as starting guesses for Plot(X,Y)
numerical methods discussed
Analytical solving

• F(x)=5x-10=0
• root(f(x)) is x=2 ➔ f(2)=5*2-10=0
• F(X) =5x2+3x-4=0
• There are two roots
−𝑏+ 𝑏2 −4𝑎𝑐
• X1= = -2.0566
2𝑎
−𝑏− 𝑏2 −4𝑎𝑐
• X2= = -3.9434
2𝑎
P1.m Matlab code
a= input('a=');
b= input('b=');
c= input('c=');
x1=-b+sqrt(b^2-4*a*c)/(2*a)
x2=-b-sqrt(b^2-4*a*c)/(2*a)
Problem Statement. Newton’s second law
• Problem
• Newton’s second law, used for calculation the parachutist’s velocity:
𝑐
𝑔𝑚 − 𝑚 𝑡
•𝑣= (1 − 𝑒 ) v as a function of t
𝑐
• Given
• Parachutist’s mass m
• drag coefficient c
• freefalling time t
• gravity is 9.81 m/s2.
• You can easily find the parachutist's velocity after freefalling for time t
• Direct substitution

• What happens if we know the parachutist’s velocity,


and we want to determine the drag coefficient c ??????
Problem Statement. Newton’s second law
• Problem
• Use the graphical approach to determine the drag coefficient c needed for a
parachutist of mass m=68.1 kg to have a velocity of v=40 m/s after freefalling
for time t=10 s. Where, the parachutist’s velocity
𝑐
𝑔𝑚 − 𝑡
• 𝑣= (1 −𝑒 𝑚 ) v as a function of t
𝑐
• Note: The acceleration due to gravity is 9.81 m/s2.
• Solution.
• This problem can be solved by determining the root of Eq.
𝑐
𝑔𝑚 − 𝑚 𝑡
•𝑓 𝑐 = 1−𝑒 −𝑣 =0
𝑐
• using the parameters t=10, g=9.81, v=40, and m=68.1:
• See the following graphical method…
Problem Statement. Newton’s second law
t=10;
g=9.81
v=40;
m=68.1;
c=-4:4:20 % suggest a range of c
%c=-4:0.1:20 % suggest a range of c
%c=-4:0.01:20 % suggest a range of c
fc=g*m./c.*(1-exp(-(c./m)*t))-v
h=plot(c,fc)
%to make x axis passes through
original point
ax = gca; %get current axis
ax.XAxisLocation = 'origin';
ax.YAxisLocation = 'origin’;

Visual inspection of the plot provides a rough estimate


of the root of 14.8.
c=14.8
fc=g*m./c.*(1-exp(-(c./m)*t))-v
➔fc= 0.0022 which is close to zero.
which is very close to the desired fall velocity of
40 m /s.
Solving non-linear equation using numerical
methods
• Bracketing Methods:
• To find roots of equations.
• They deals with methods that exploit the fact that
• a function typically changes sign in the vicinity (neighborhood) of a
root.
• These techniques are called bracketing methods because two initial guesses for
the root are required. Each guess makes
• Ex: The Bisection Method

• Open Methods
• The Newton-Raphson Method
• The Secant Method
Solving non-linear equation using Bisection Method

We wish to find a root to the equation f(x)=0 in the interval [a,b]

f (b)  0
f ( x)

a b

f (a)  0
The root at which f ( x ) = 0
Solving non-linear equation using Bisection Method

Step 1: Choose lower 𝑥𝑙 and upper 𝑥𝑢 guesses for the root such that the function
changes sign over the interval. This can be checked by ensuring that 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑢 ) < 0.

Step 2: An estimate of the root 𝑥𝑟 is determined by


𝑥𝑙 + 𝑥𝑢
𝑥𝑟 =
2
Step 3: Make the following evaluations to determine in which subinterval the root lies:
(a) If 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) < 0,
- the root lies in the lower subinterval.
- therefore, set 𝑥𝑢 = 𝑥𝑟 and return to step 2.
(b) If 𝑓(𝑥𝑟 ) 𝑓(𝑥𝑢 ) > 0
- the root lies in the upper subinterval.
- therefore, set 𝑥𝑙 =𝑥𝑟 and return to step 2.
(c) If 𝑓(𝑥𝑙 ) 𝑓(𝑥𝑟 ) = 0, the root equals 𝑥𝑟 ; terminate the computation.
•Using bisection, solve the 𝑓 𝑥 = 𝑥 3 − 𝑥 − 11 on the
interval [2,3] until the approximate error falls below a
stopping criterion of 𝜀𝑠 = 0.5%.
−ve +ve
𝑥𝑙 + 𝑥𝑢 𝑥𝑟 −𝑥𝑟−1 𝑓(𝑥𝑟 )
𝑥𝑙 𝑥𝑢 𝑥𝑟 = 𝜀𝑎 = | 𝑥𝑟
|*100
2

2 3 2.5 −−−−− +ve


2 2.5 2.25 11.111% −ve
2.25 2.5 2.375 5.2% +ve
2.25 2.375 2.3125 2.7% −ve
2.3125 2.375 2.34375 1.33% −ve
2.34375 2.375 2.359375 0.6% −ve
2.359375 2.375 2.3671875 0.33% −ve
2.3671875 2.375 2.3710938 0.164% −ve
2.3710938 2.375 2.3730469 0.0823% −ve
2.3730469 2.375 2.3740235 0.0411%
Bisection Method
clear
clc
f ( x) = x3 − x − 11
syms x;
fx=x^3-x-11;
xl=2;
xu=3;
e=0.05;
numberOfIteration=100;
if subs(fx,xl)*subs(fx,xu)<0
names={'-ve','+ve','xn','error'};
for i=1:numberOfIteration
xr=(xl+xu)/2;
if i==1
data(i,:)=[xl,xu,xr,9999];% no error
else
error=abs((xr-xrold)/xr)*100;
if (error<e)
break
end
data(i,:)=[xl,xu,xr,error];
end

if subs(fx,xl)*subs(fx,xr)<0
xu=xr;
else
xl=xr;
end
xrold=xr;
end
t=uitable('ColumnName',names,'Data',data,'Position',[100
100 410 200]);
else
disp('no solution')
end
Problem Statement. Newton’s second law
• Problem
• Using Bisection Method on the interval [12,16], determine the drag coefficient c
needed for a parachutist of mass m=68.1 kg to have a velocity of v=40 m/s after
freefalling for time t=10 s. Where, the parachutist’s velocity
𝑐
𝑔𝑚 − 𝑚 𝑡
• 𝑣= 𝑐
(1 − 𝑒 ) v as a function of t
• Note: The acceleration due to gravity is 9.81 m/s2.
• Error= 0.5%
Drawbacks of Bisection Method

Drawbacks
• Converges very slowly
• Requires two guess points
Notes
Illustration of a number of general ways that a root may
occur in an interval prescribed by a lower bound xl and an
upper bound xu.
• Parts (a) and (c) indicate that if both f (xl) and f
(xu) have the same sign, either there will be no
roots or there will be an even number of roots
within the interval.

• Parts (b) and (d ) indicate that if the function has


different signs at the end points, there will be an
odd number of roots in the interval.
Notes
Illustration of some exceptions to the general
cases depicted in
Part (a) Multiple root that occurs when
the function is tangential to the x axis.
For this case, although the end points are
of opposite signs, there are an even
number of axis intersections for
the interval.

(b) Discontinuous function where end


points of opposite sign bracket an even
number of roots. Special strategies are
required for determining the roots for
these cases.
Problem 5.1
Determine the real roots of f (x) = −0.6x2 + 2.4x + 5.5:
(a) Graphically.
(b) Using the quadratic formula.
(c) Using three iterations of the bisection method to determine the
highest root. Employ initial guesses of xl = 5 and xu = 10.
Compute the estimated error εa and the true error εt after each iteration.
Problem 5.17
• You are designing a spherical tank to hold water for a small village in a
developing country. The volume of liquid it can hold can be computed
as
• V = πh2 [3R − h]/3
• where V = volume [m3], h = depth of water in tank [m], and R = the tank
radius [m].
• If R = 3 m, to what depth must the tank be filled so that it holds 30 m3?
• Use three iterations of the bisection method to determine your answer.
• Determine the approximate relative error after each iteration. Employ initial
guesses of 0 and R.
Problem 1
• By using Bisection method, find an iterative formula to find the value of
where is a positive real number and hence use this formula to
approximate the following square roots with an error less than 0.001 %
• (a) 5 (b) 12

You might also like