��������� ������� ��� ��������� ���� 223 ���� �� : ����� �� ��������
��. ����� ������ ���������� ������ �������� 2007/2008
Numerical methods for engineers (COEB223): Part II
������������ �� ���� �� ����� �� ���������
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
2
Numerical methods for engineers (COEB223): Part II
������������ �� ���� �� ����� �� ���������
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
2
Numerical methods for engineers (COEB223): Part II
Actual beginning of Numerical Methods is from this point. Polynomial;
f n ( x ) = a0 + a1x + a2 x 2 + ...an x n
y = f ( x ) is algebraic if if it can be expressed in the form n
f n y + f n −1 y
n −1
+ ... + f1 y + f 0 = 0
where f i is an ith th order order polynomial Transcendental equations contain non-algebraic expressions exponential, trigonometric, logarithmic and other functions. For example f ( x ) = e−0.2 x sin ( 3x − 0.5)
Roots of Equ Equations.: ations.: ’ The value of x which makes f(x)=0 are called roots or 'zeros of the equation. For quadratic equation roots can be found by a standard s tandard formula. Other equations, it is difficult. Two types of problems would be dealt with here. 1. Real roots of algebraic and transcendental equations 2. Complex roots of polynomials. Methods for finding the roots: 1. Graphical Methods (Ch 5) 2. Bracketing Methods (Ch 5) a) Bisection Method b) False Position Method (Regula Falsi)
3. Open Methods (Ch 6) a) Fixed point iteration b) Newton-Raphson Method c) Secant Method 4. Muller’s and Bairstow’s methods for polynomial roots (ch 7)
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
3
Numerical methods for engineers ( OEB223): Part II
������� 7 ������� 5 � 5.1��������� ������� � 5.2 ��������� � 5.3 � ��� ��������
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
4
Numerical methods for engineers (COEB223): Part II
5.0 Bracketing Methods • Method that exploit the fact that a function typically
changes sign in the vicinity of a root. • It is called ‘bracketing method’ – need 2 initial guesses on either side (‘bracketing’) of the root 5.1 Graphical method
- of limited practical value since are not precise, however can be employed as starting guesses for numerical method example 1: Determine the 'drag coefficient’, c, required for a parachutist of mass m = 68.1 kg to have a velocity of 40 m/s after free-falling 2 for a time of t= 10s. Assume g= 9.8 m/s . Solution: The relation between velocity and time and c are given by the relation: gm − c m t v (t ) = 1− e ( ) c It is given that at t= 10s, v= 40 m/s and we should find c. Notice that c is implicit (cannot rearrange c to one side of the equation). Thus let us define a function f (c) as follows:
(
f (c ) =
gm c
)
(1 − e (
− c m ) t
)−v
the value of 'c' which makes f(c) = 0 is the required value i.e. we require the root of f(c).Substitute value, f (c ) =
if c=4,
f (c ) =
9.8(68.1) 4
9.8(68.1) c
(1 − e (
− 4 68.1)1 0
(1 − e (
− c 68.1)10
) − 40 = 34.115 ,
) − 40
so do for other values
as in the table and plot the graph to see where it intersect. By Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
5
Numerical methods for engineers ( OEB223): Part II
visual inspection the rough estimate of the root is 14.75. This should be check a ain by substituting to f(c) and , where we want close to f(c)=0 and v=40.
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
6
Numerical methods for engineers (COEB223): Part II
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
7
Numerical methods for engineers (COEB223): Part II
5.2 Bisection Method
a) If f(xl) f(xr)<0 then xu=xr and return to step 2 b) If f(xl) f(xr)>0 then xl=xr and return to step 2 c) If f(xl) f(xr)=0 then xr is the root.
note: f (c) = Iteration xl 1 12 2 14 3 14 4 14.5 5 14.75 6 14.75
9.8(68.1) c
(
1− e
− ( c 68.1)10
xu xr 16 14 16 15 15 14.5 15 14.75 15 14.875 14.875 14.8125
) − 40 from example 1.
fl 6.0669 1.5687 1.5687 0.5523 0.059 0.059
fr 1.5687 -0.425 0.5523 0.059 -0.184 -0.063
f(xl)*f(xr) 9.5172834 -0.666438 0.8664426 0.0325668 -0.010856 -0.003707
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
ea(%) et(%) 5.2787 6.6667 1.4871 3.4483 1.8958 1.6949 0.2043 0.8403 0.6414 0.4219 0.2185
8
Numerical methods for engineers ( OEB223): Part II
Figure for the first t ree iterations.
5.3 False Positio Method (Other names: Regula Falsi, Linear Interpolation Met od)
The Bisection met f(xu) in determinin with less effort if straight relation bet
od does not take the magnitude of f(xl) and the value of xr . Final value can be reached e assume a false position for xr assuming a een f(xl) and f(xu).
Calculate f( xr ) and f nd its sign. f( xr ) will replace the (xu) or f( xl) whichever has th same sign as f( xr ). Thus xr will always bracket the root. 1) Calculate xr usin the above equation a) If f(xl) f(xr)<0 then xu=xr and return to step 1 b) If f(xl) f(xr) 0 then xl=xr and return to step 1 Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
9
Numerical methods for engineers ( OEB223): Part II
c) If f(xl) f(xr) 0 then xr is the root.
See Sec.5.3.1, Pitfalls of the False-Position Method Note: Always heck by substituting estimated r ot in the original equation to determine whether f(xr) ≈ 0. See example proble Itera tion xl
xu
5.5 and 5.6. fxl
fxu
xr
fr
f(xl)*f(xr)
ea(%)
et(%)
1
12
16
6. 6695 -2.26875 14.9113 -0.254277
-1.54269
2
12
14.9113
6. 6695 -0.25426 14.7942 -0.027256
-0.16536 0.7916 0.0947
3
12
14.7942
6. 6695 -0.02726 14.7817 -0.002908
-0.01764 0.0845 0.0102
4
12
14.7817
6. 6695
-0.00188
-0.00291 14.7804
-0.00031
Example: Problem 5.3 5.3 Determine the eal root of f ( x) = −25 + 82 x 90 x 2 + 44 x3 − 8x4 + 0.7 x5 (a) Graphically (b) Using bisection, xl = 0.5 , xu = 1 , ε s (c)
Using fa se-position, xl
0.887
0.009
= 10%
= 0.5 , xu = 1 ,
ε s = %
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
10
0.0011
Numerical methods for engineers (COEB223): Part II
Solution: (a) A plot indicates that a single real root occurs at about x = 0.58. 8 4 0 -4
0
0.5
1
1.5
-8
(b) Bisection:
First iteration: x r =
0.5 + 1 2
= 0.75 ε a =
1 − 0.5 1 + 0.5
× 100% = 33.33%
f (0.5) f (0.75) = −1.47813(2.07236) = −3.06321 Therefore, the new bracket is xl = 0.5 and xu = 0.75.
iterati on 1
f (x l) ×f ( x l
x u
x r
0.500
1.000
0.750
00
00
00
f (x l)
f (x r)
x r)
ε εa
2 3 4
(c) False position: First iteration: xl = 0.5 f ( xl) = –1.47813 xu = 1 f ( xu) = 3.7 xr = 1 −
3.7(0.5 − 1) − 1.47813 − 3.7
= 0.64273
f (0.5) f (0.64273) = −1.47813(0.91879 ) = −1.35808
Therefore, the bracket is xl = 0.5 and xu = 0.64273. Second iteration:
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
11
Numerical methods for engineers (COEB223): Part II
iteration xl xu 1 0.5 1.00000 2 3 4
f ( xl )
f ( xu)
x r
f ( x r)
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
f ( xl )× f ( x r)
12
ε ε a
Numerical methods for engineers ( OEB223): Part II
������� 8 ������� 6 � 6.1 ������ ����������� ��������� � 6.2 �������������� � 6.3 � ���� �������
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
13
Numerical methods for engineers (COEB223): Part II
6. 0 Open Methods Figure 6.1: Difference between (a) bracketing and (b),(c) open methods for root location. (b) the method diverge, (c) the method converge, depending on the initial guess.
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
14
Numerical methods for engineers ( OEB223): Part II
6.1 Single Fixed-P int Iteration
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
15
Numerical methods for engineers (COEB223): Part II
6.2 Newton-Raphson method
•
Most widely used method. Based on Taylor series expansion:
f ( xi +1 ) = f ( xi ) + f ′( xi ) ∆x + f ′′( xi )
The root is the value of x i +1
∆ x
2
+ O ∆x
3
2! when f(x i +1 ) = 0
Rearranging, ′ i )( xi +1 − xi ) 0 = f(xi ) + f (x
xi +1 = xi −
f ( xi )
f ′( xi ) •A convenient method for functions whose derivatives can be evaluated analytically. It may not be convenient for functions whose derivatives cannot be evaluated analytically. See example 6.3 Figure 6.5
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
16
Numerical methods for engineers (COEB223): Part II
Figure 6.6 Poor convergence of Newton-Raphson
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
17
Numerical methods for engineers (COEB223): Part II
6.3 Secant Method •A slight variation of Newton’s method for functions whose derivatives are difficult to evaluate. For these cases the derivative can be approximated by a backward finite divided difference.
f ′( x i ) ≅
xi +1 = xi − f ( xi )
x i − xi −1 f ( x i ) − f ( x i −1 )
xi − xi −1 f ( xi ) − f ( xi −1 )
i = 1, 2,3,K
Figure 6.7 : The secant method is similar to Newton-Raphson technique – extrapolate tangent of the function (figure 6.5) , however here a ‘difference’ is used rather than ‘derivative’.
•Requires two initial estimates of x , e.g, xo, x1. However, because f(x) is not required to change signs between estimates, it is not classified as a “bracketing” method.
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
18
Numerical methods for engineers (COEB223): Part II
•The secant method has the same properties as Newton’s method. Convergence is not guaranteed for all x o, f(x). Example 6.6 figure 6.8
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
19
Numerical methods for engineers (COEB223): Part II
Example Problem 6.2 3 2 f ( x ) = 2 x − 11.7 x + 17.7 x − 5
(b) fixed point iteration - xi +1 = g ( x ) x =
i 0 1 2 3
5− 2
3
+ 11.7 x
2
17.7
xi 3 3.1808 3.334 3.4425
(%)εa 5.68 4.595 3.152
f ( xi )
(c) Newton-Raphson xi +1 = xi − f ′( x ) i i 0 1 2 3
xi 3 5.1333 4.26975 3.7929
(d) secant i 0 1 2 3
xi-1 3 4 3.3265 3.4813
f(xi) -3.2 48.0882 12.96
xi +1 = xi − f ( xi )
f(xi-1)
f’(xi) 1.5 55.6854 27.18
xi − xi −1
41.5580% 20.14 12.57 i = 1, 2, 3,K
f ( xi ) − f ( xi −1 )
xi 4
εa
f(xi)
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
εa
20.25 4.44 2.93
20
Numerical methods for engineers ( OEB223): Part II
������� 9 ����� � 7 : ����� �� ���������� � 7.4 �������� ������
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
21
Numerical methods for engineers (COEB223): Part II
7.0 Roots of Polynomials • The roots of polynomials such as 2
f n ( x) = ao + a1 x + a2 x + K + an x
n
Follow these rules: 1.For an nth order equation, there are n real or complex roots. 2.If n is odd, there is at least one real root. 3.If complex root exist in conjugate pairs (that is, λ + µ i and λ - µ i), where i=sqrt(-1). Conventional Methods • The efficacy of bracketing and open methods depends on whether the problem being solved involves complex roots. If only real roots exist, these methods could be used. However, – Finding good initial guesses complicates both the open
and bracketing methods, also the open methods could be susceptible to divergence.
• Special methods have been developed to find the real and complex roots of polynomials – M �ller and Bairstow methods.
7.4 Müller’s method
•Müller’s method obtains a root estimate by projecting a parabola to the x axis through three function values. •The method consists of deriving the coefficients of parabola that goes through the three points.
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
22
Numerical methods for engineers (COEB223): Part II
Figure 7.3: comparison between (a) secant method (b) Muller’s method 1. Write the equation in a convenient form: f 2 ( x) = a( x − x2 ) 2 + b( x − x2 ) + c
2.The parabola should intersect the three points [xo , f(xo)], [x1, f(x1)], [x2 , f(x2)]. The coefficients of the polynomial can be estimated by substituting three points to give f ( xo ) = a ( xo − x2 ) 2 + b ( xo − x 2 ) + c f ( x1 ) = a ( x1 − x2 ) 2 + b (x1 − x 2 ) + c f ( x2 ) = a ( x2 − x2 ) 2 + b ( x 2 − x 2 ) + c
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
23
Numerical methods for engineers (COEB223): Part II
3.Three equations can be solved for three unknowns, a, b, c. Since two of the terms in the 3 rd equation are zero, it can be f ( xo ) − f ( x2 ) = a ( xo − x2 ) 2 + b( xo − x2 ) 2
f ( x1 ) − f ( x2 ) = a ( x1 − x2 ) + b( x1 − x2 )
If h o = x1 - x o
δ o =
h1 = x 2 - x 1
f ( x1 ) − f ( xo ) x1 − xo
δ 1 =
f ( x2 ) − f ( x1 ) x2 − x1
(ho + h1 )b − (ho + h1 ) 2 a = hoδ o + h1δ 1 h1b − h12 a = h1δ 1
a=
δ 1 − δ o
b = ah1 + δ 1
h1 + ho
c = f ( x2 )
immediately solved for c=f(x2). •Roots can be found by applying an alternative form of quadratic formula: x3 = x2 +
− 2c
b ± b 2 − 4ac
•The error can be calculated as
ε a
=
x3 − x2 x 3
100%
•• ±term yields two roots, the sign is chosen to agree with b. This will result in a largest denominator, and will give root estimate that is closest to x 2. •Once x3 is determined, the process is repeated using the following guidelines: 1.If only real roots are being located, choose the two original points that are nearest the new root estimate, x3.
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
24
Numerical methods for engineers (COEB223): Part II
2.If both real and complex roots are estimated, employ a sequential approach just like in secant method, x1 , x2, and x3 to replace xo , x1, and x2. See example 7.2 Using MATLAB to determine all roots: 3
2
If f ( x) = x − x + 3 x − 2 >> a=[1 -1 3 -2]; >> roots(a) ans = 0.1424 + 1.6661i 0.1424 - 1.6661i 0.7152 see example 7.6 and 7.7 Example : Problem 7.3 (a) Use Muller method to determine the positive real root:
f ( x) = x3 + x2 − 3 x − 5
A plot indicates a root at about x = 2. 60 40 20 0 -4
-2
-20 0
2
4
-40
Try initial guesses of x0 = 1, x1 = 1.5, and x2 = 2.5. Using the same approach as in Example 7.2, First iteration: Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
25
Numerical methods for engineers (COEB223): Part II
f (1) = –6 f (1.5) = –3.875 9.375 h0 = 0.5 h1 = 1 δ 0 = 4.25 δ 1 = 13.25 13.25 − 4.25 a= =6 1 + 0.5 b = 6(1) + 13.25 = 19.25
f (2.5) =
c = 9.375 x3 = 2.5 +
ε a
− 2(9.375) 2
= 1.901244
19.25 + 19.25 − 4(6)(9.375) =
1.901244 − 2.5 1.901244
× 100% = 31.49%
The iterations can be continued as tabulated below: i 0 1 2 3
x3 ε ε a 1.901244 31.4929% 1.919270 0.9392% 1.919639 0.0192% 1.919640 0.0000%
3
2
7.3 b) for f ( x) = x − 0.5 x + 4 x − 3 Try initial guesses of x0 = 0.5, x1 = 1, and x2 = 1.5 ?
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
26
Numerical methods for engineers ( OEB223): Part II
���� �� 10 ����� � 7 : ����� �� ����� ���� � 7.5 ��������'� ������
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/200
27
Numerical methods for engineers (COEB223): Part II
7.5 Bairstow’s Method • Bairstow’s method is an iterative approach loosely related to both Müller and Newton Raphson methods. • It is based on dividing a polynomial by a factor x-t:
f n ( x ) = ao + a1 x + a2 x 2 + K + an x n f n −1 ( x) = b1 + b2 x + b3 x 2 + K + bn x n
with a reminder R = b o , the coefficients are calculated by recurrence relationship bn = an bi =a i +bi +1t i = n − 1 to 2
• To permit the evaluation of complex roots, Bairstow’s method divides 2 the polynomial by a quadratic factor x -rx-s:
f n − 2 ( x) = b2 + b3 x + K + bn −1 x
n −3
+ bn x
n−2
R = b1 ( x − r ) + bo
Using a simple recurrence relationship bn = an bn-1 = an-1 + rbn bi = ai + rbi +1 + sbi + 2
i = n-2 to 0
• For the remainder to be zero, bo and b1 must be zero. However, it is unlikely that our initial guesses at the values of r and s will lead to this result, a systematic approach can be used to modify our guesses so that bo and b1 approach to zero.
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
28
Numerical methods for engineers (COEB223): Part II
• Using a similar approach to Newton Raphson method, both bo and b1 can be expanded as function of both r and s in Taylor series.
∂b1
b1 ( r + ∆r , s + ∆s ) = b1 +
∂r
bo (r + ∆r , s + ∆s ) = bo +
∆r +
∂bo ∂r
∂b1
∆r +
∂s
∆s
∂bo ∂s
∆s
assuming that the initial guesses are adequately close to the values of r and s at roots. The changes in ∆s and ∆r needed to improve our guesses will be estimated as ∂b1 ∂r ∂bo ∂r
∂b1
∆r +
∂s ∂bo
∆r +
∂s
∆s = −b1 ∆s = −bo
• If partial derivatives of the b’s can be determined, then the two equations can be solved simultaneously for the two unknowns ∆r and ∆s . • Partial derivatives can be obtained by a synthetic division of the b’s in a similar fashion the b’s themselves are derived:
cn = bn cn −1 = bn−1 + rcn ci = bi + rci +1 + sci + 2
i = n − 2 to 1
where ∂bo ∂r
= c1
∂bo ∂s
=
∂b1 ∂r
= c2
∂b1 ∂s
= c3
• Then
c2 ∆r + c3∆s = −b1
∆r
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
c1∆r + c2 ∆s = −bo
∆s
Solved for and , in turn are 29 employed to improve the initial guesses.
Numerical methods for engineers (COEB223): Part II
• At each step the error can be estimated as
ε a ,r
=
ε a , s
=
∆r
r ∆s
s
100% 100%
When both of these error estimates fall below a prespesified stopping criteria, the roots can be determined 2
x =
r ± r + 4s
2
if the quotient is a first order, since, f n −2 ( x ) = b2 + b3 x = 0
x =
−b2
b3
See example 7.3 Refer to Tables pt2.3 and pt2.4
7.5 (a) Use Bairstow’s method to determine the roots:
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
30
Numerical methods for engineers (COEB223): Part II
2
f ( x) = −2 + 6.2 x − 4 x + 0.7 x
3
A plot suggests 3 real roots: 0.44, 2 and 3.3. 4 2 0 -2
0
1
2
3
4
-4
2
f ( x) = −2 + 6.2 x − 4 x + 0.7 x ao = − 2
a1 = 6.2
a2 = −4
3
a3 = 0.7
st
1 iteration: Try r = 1 and s = –1
b3 = a 3 = b 2 = a 2 + r b3 = n=3, b1 = a 1 + r b 2 + s b 3 =
bo = solve simultaneous eqn using calculator casio fx-570s: a1 x + b1 y = c1 a2 x + b2 y = c2
MODE MODE MODE Choose 1 EQN Unknowns 2 a1? -2.6= b1? And so on.. will give x and y which are the ∆r and ∆s
Dr. Hanim Salleh, Mechanical Engineering, UNITEN, 2007/2008
31