Professional Documents
Culture Documents
Yajing Shen 1
Review
Root of equation: f(x)=0
Graphical Method
Given a series of x to calculate f(x)
f(x)
Review
Root of equation: f(x)=0
Automatic Methods f(x) Figure 5.4
Bracketing methods
Review
Root of equation: f(x)=0
Automatic Methods
Bracketing methods xL xr xU
Bisection method
f(x)
1. Check the sign: f (xL)f(xU)
2. Calculate the root: xr
3. Check the root: f(xr) f(xL)
x
Review
Error Analysis for Bisection Method
The approximate percent relative error:
xU xL
2 x xL
a = 100% = U 100% Eq 5.10
xU + xL xU + xL
2
x 0
n = log 2
Eq 5.12
E A,d
MBE 2036
Roots of Equations Open Methods
Part 6
Newton-Raphson Method
It is one of the most widely root-locating
method.
If the initial guess is xi, a tangent can be
extended from the point [xi , f(xi)] (see
figure 6.1).
The point where this tangent crosses the x
axis usually represents an improved
estimate of the root (see figure 6.1).
f(xi)
f(xi)-0
x
xi+1 xi
xi xi+1
Figure 6.1
Example 1
Problem statement: Use the Newton-Raphson
method to estimate the root of f(x)=e-x - x,
employing an initial guess of x0=0. The true value
of the root is 0.56714329.
Solution: Evaluate the first derivative:
f ' (x) = e x 1 Eq 6.3
Eq 6.3 can be substituted along with the original
function in Eq 6.2 to give
e xi xi
xi +1 = xi
e 1 xi
( Eq 6.4
)
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing part 6, Dr. Yajing Shen 12
Example 1(cont)
Starting with an initial guess of x0=0
When i=0: True value Estimate
x0=0
the initial error =0.56714329 -0 = 0.56714329
The true percent relative error =100%
0
True value - Approxima tion
t = 100% Eq 3.1
True value
When i = 1: e x0 x0 0
x = x0 = 0.5
From Eq 6.4, 1 ( e 1)
x0
Example 1(cont)
0.5
e x1 x1
When i=2: x2 = x1 = 0.566311003
( e 1)
x1
Example 1 (cont)
i xi True error t (%) a (%)
0 0 0.56714329 100
4 0.567143290 0 0 0.000022
Example 2
Remember the previous problem of finding the
drag coefficient c for a parachutist in Lecture
Handout 5: m=68.1kg, g=9.8m/s2, v=40m/s
c
m t
f(c) = g(1 - e m ) - v = 0 Eq. 5.3
c
667.38
f(c) = (1 e 0.146843c ) 40 Eq 5.5
c
This is to find c which will make Eq 5.5 to zero
In Handout 5, we use the Bisection Method to
solve the problem. Now, we will try the Newton-
Raphson Method
The true root of the Eq 5.5 is 14.7802085
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing part 6, Dr. Yajing Shen 16
Example 2
If we let k1=667.38 and k2=0.146843, Eq 5.5
can be rewritten as: n
dx
k1 k1 k2c = nx n1
f(c) = e 40 Eq6.5 dx
c c d ( k1c 1 ) k1dc 1
d (uv )
=u
dv
+v
du = = k1c 2
dx dx dx dc dc
d40
=0
d k1 k1 k2c d dc
f ' (c) = e 40 = (k1c 1 k1c 1e k2c 40)
dc c c dc
( )
k2 c 1
d 1 k 2 c 1 de k 2 c dc
k1c e = k1c + k1e
dc dc dc
f ' (c) = k1c 2 (k1c 1( k 2 e k2c )) (e k2c ( k1c 2 ))
f ' (c) = k1c 2 + (k1c 1k 2 e k2c ) + (e k2c k1c 2 ) Eq 6.6
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing part 6, Dr. Yajing Shen 17
Example 2 (cont)
Substitute Eq 6.5 and 6.6 into Eq 6.2
-1 k2ci
k1ci k1ci e 40
-1
ci +1 = ci 2 1 k2ci k2ci 2
k1ci + (k1ci k 2 e ) + (e k1ci )
Example 2 (cont)
The true error = 14.7802085-14.48967087
=0.29053763
14.7802085 - 14.4896708 7
t = 100% = 1.96572072 %
14.7802085
Example 2 (cont)
i xi True error t (%) a (%)
0 12
Example 2 (cont)
Bisection Method
Iterati
on
xL xU xr t (%) a (%)
1 12 16 14 5.2787
2 14 16 15 1.4871 6.667
Error Estimates
The error Et,i+1=xr xi+1, where xr is the true root
and xi+1 is the estimated root
Using Taylor series method, the true error can be
written as:
f '' (xr ) 2
E t,i+1 '
E t,i Eq 6.7
2f (xr )
Thus the error is roughly proportional to the
square of the previous error.
This means that the number of correct decimal
places approximately doubles with each iteration
This is referred to as quadratic convergence
x1 x0
x2
x
Figure 6.2
x2 x0 x3 x1
x
Figure 6.3
x1
x0 x
Figure 6.4
An initial guess that is close to one root can jump to a location several roots
away. This tendency to move away from the area of interest is because near-
zero slopes are encountered.
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing part 6, Dr. Yajing Shen 26
x0 x1 x
Figure 6.5
the solution shooting off horizontally and never hits the x axis. This is caused
by a zero slope (i.e. f(x) = 0)
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing part 6, Dr. Yajing Shen 27
f(xi 1 ) f(xi )
f (xi )
'
Eq 7.1
xi 1 xi
f(xi-1)
x
xi+1 xi-1 xi
Figure 7.1
Example 1
Problem statement: Use the Secant method to
estimate the root of f(x)=e-x - x, employing two
initial guesses of x-1=0 and x0=1. The true value
of the root is 0.56714329.
Solution:
First iteration:
x-1 = 0 f(x-1) = e0 -0 = 1.0
Example 1 (cont)
0.56714329 - 0.61270
t = 100% = 8.032%
0.56714329
Second Iteration:
0.56714329 - 0.56384
t = 100% = 0.5823%
0.56714329
Example 1 (cont)
Third iteration:
0.00518(0.6127 - 0.56384)
x3 == 0.56384 - = 0.56717
- 0.07081 - (-0.00518)
0.56714329 - 0.56717
t = 100% = 0.00471%
0.56714329
Example 2
Problem statement: Use the Modified Secant
method to estimate the root of f(x)=e-x - x,
employing =0.01 and an initial guess of x0=1.
The true value of the root is 0.56714329.
Solution:
First iteration:
x0 = 1 0.01 x 1 f(x0) = e-1 -1 = 0.367879 1 = -0.63212
Example 2
Second iteration:
x1 = 0.537263 f(x1) = e-0.537263 -0.537263 = 0.047083
Third iteration:
x2 = 0.56701 f(x2) = 0.000209
x2 + x2 = 0.567143 f(x2+ x2 ) = -0.00867
0.0056701(0.000209)
x3 = 0.56701 - = 0.567143
- 0.00867 - 0.000209
t = 2.365 10 -5%
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing part 6, Dr. Yajing Shen 38
Learning Outcomes
After this lecture, the student would be able to understand the
following:
Sequence
Matlab example:
x=3
y=x+5;
z=x*y;
Selection
Matlab example:
if x<0
y=-10;
else if x>0
y=10;
else
y=0;
end
Iteration
Matlab example:
for i=0:2:20
x=x+i;
end
Another iteration
Matlab example:
while (1)
i=i+1;
y=x^2;
end
function mainprog
m=68.1;
g=9.8; function myvelocity(m,g,c,t)
c=0.25;
t=0:2:12;
v1=velocity_profile(m,g,c,t)
Appendix
Error estimates of
Newton-Raphson Method
f (n ) (x0 )
Taylor series: f ( x0 + x) = f ( x) = f ( x0 ) + f ( x0 )( x x0 ) + ... + ( x x 0 )n + R n ( x )
n!
f ( n +1) ( )
Rn ( x ) = (x x0 )n+1 ,
(n + 1)
So, we have: = + + 2
2!
Noted that: = 0
Therefore:
+ + 2
=0
2!
+ +1 = 0
Error estimates of
Newton-Raphson Method
Thus, subtracting the following two equations:
+ + 2 = 0
2!
+ +1 = 0
We have:
+1 + 2
=0
2!
f(x)=e-x - x