Secant Method Nonlinear Equations

Download Report

Transcript Secant Method Nonlinear Equations

Secant Method
Chemical Engineering Majors
Authors: Autar Kaw, Jai Paul
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates
7/17/2015
http://numericalmethods.eng.usf.edu
1
Secant Method
http://numericalmethods.eng.usf.edu
Secant Method – Derivation
Newton’s Method
f(x)
x f x 
f(xi)
i,
xi 1 = xi -
i
f(xi )
f (xi )
(1)
Approximate the derivative
f ( xi ) 
f(xi-1)

xi+2
xi+1
xi
X
Figure 1 Geometrical illustration of
the Newton-Raphson method.
3
f ( xi )  f ( xi 1 )
xi  xi 1
(2)
Substituting Equation (2)
into Equation (1) gives the
Secant method
xi 1
f ( xi )(xi  xi 1 )
 xi 
f ( xi )  f ( xi 1 )
http://numericalmethods.eng.usf.edu
Secant Method – Derivation
The secant method can also be derived from geometry:
f(x)
f(xi)
The Geometric Similar Triangles
AB DC

AE DE
B
can be written as
f ( xi )
f ( xi 1 )

xi  xi 1 xi 1  xi 1
C
f(xi-1)
xi+1
E D
xi-1
A
xi
X
Figure 2 Geometrical representation of
the Secant method.
4
On rearranging, the secant
method is given as
xi 1
f ( xi )(xi  xi 1 )
 xi 
f ( xi )  f ( xi 1 )
http://numericalmethods.eng.usf.edu
Algorithm for Secant Method
5
http://numericalmethods.eng.usf.edu
Step 1
Calculate the next estimate of the root from two initial guesses
xi 1
f ( xi )(xi  xi 1 )
 xi 
f ( xi )  f ( xi 1 )
Find the absolute relative approximate error
xi 1- xi
a =
 10 0
xi 1
6
http://numericalmethods.eng.usf.edu
Step 2
Find if the absolute relative approximate error is greater
than the prespecified relative error tolerance.
If so, go back to step 1, else stop the algorithm.
Also check if the number of iterations has exceeded the
maximum number of iterations.
7
http://numericalmethods.eng.usf.edu
Example 1
You have a spherical storage tank containing oil. The tank has a
diameter of 6 ft. You are asked to calculate the height, h, to which a
dipstick 8 ft long would be wet with oil when immersed in the tank
when it contains 4 ft3 of oil.
Dipstick
Spherical Storage Tank
r
h
Figure 2 Spherical Storage tank problem.
8
http://numericalmethods.eng.usf.edu
Example 1 Cont.
The equation that gives the height, h, of liquid in the spherical tank
for the given volume and radius is given by
f(h)  h3  9h2  3.8197 0
Use the secant method of finding roots of equations to find the
height, h, to which the dipstick is wet with oil. Conduct three
iterations to estimate the root of the above equation. Find the
absolute relative approximate error at the end of each iteration and
the number of significant digits at least correct at the end of each
iteration.
9
http://numericalmethods.eng.usf.edu
Example 1 Cont.
3.82
20
0
0
20
40
f ( x)
60
80
100
 104.18
120
0
1
2
3
4
5
x x guess 1 x guess 2
0
6
6
f(x)
Figure 3 Graph of the function f(h)
f(h)  h3  9h2  3.8197 0
10
http://numericalmethods.eng.usf.edu
Example 1 Cont.
Solution
7.57
Initial guesses of the root:
h1  0.5 and h0  1.
20
0
0
Iteration 1
The estimate of the root is
f h0 h0  h1 
h1  h0 
f h0   f h1 
20
f ( x)
f ( x)
40
f ( x)
secant( x)
60
80

100
 104.18
120
3
0
2
0

 
 0.64423
0
1
2
3
4
5
x x 0  x 1' x x 1
0
f(x)
x'1 , (fi rst gu ess)
x0 , (p rev io us gu ess)
Secant li ne
x1 , (n ew g uess)
Figure 4 Graph of the estimated
root of the equation after
Iteration 1.
11
h
 9h02  3.8197 h0  h1 
 h0  3
h0  9h  3.8197  h31  9h21  3.8197
f ( x)
6
6
The absolute relative approximate
error is
h h
a  1 0 100
h1
 55.224 %
The number of significant digits at least
correct is 0.
http://numericalmethods.eng.usf.edu

Example 1 Cont.
8.559
20
Iteration 2
The estimate of the root is
0
0
h2  h1 
20
f ( x)
f ( x)

60
f ( x)
80
100
 104.18
120
0
1
2
3
x x 1  x 0  x x 2
0
4
5
6
6
f(x)
x1 (g uess)
x0 (p rev io u s gu ess)
Secant li n e
x2 (n ew g u ess)
Figure 5 Graph of the estimated root
after Iteration 2.
12
h

 9h12  3.8197 h1  h0 
 h1  3
h1  9h  3.8197  h03  9h02  3.8197
40
f ( x)
secant( x)
f h1 h1  h0 
f h1   f h0 
3
1
2
1
 
 0.67185
The absolute relative approximate
error is
h h
a  2 1 100
h2
 4.1104%
The number of significant digits at
least correct is 1.
http://numericalmethods.eng.usf.edu

Example 1 Cont.
Iteration 3
The estimate of the root is
f h2 h2  h1 
h3  h2 
f h2   f h1 
Entered functi on al ong gi ven interval wi th current and next root and the
tangent l ine of the curve at the curr ent root
7.145
20
0
0
f ( x)
20
f ( x)
secant( x)
80
0
1
2
3
4
5
x x 2  x 1  x x 3
0
f(x)
x2 (g uess)
x1 (p rev io u s gu ess)
Secant li ne
x3 (n ew g u ess)
Figure 6 Graph of the estimated root
after Iteration 3.
13

 
 0.67759
100
120
3
2
2
2

60
f ( x)
 104.18
h
 9h22  3.8197 h2  h1 
 h2  3
h2  9h  3.8197  h13  9h12  3.8197
40
f ( x)
6
6
The absolute relative approximate
error is
h h
a  2 1 100
h2
 0.84768%
The number of significant digits at
least correct is 1.
http://numericalmethods.eng.usf.edu

Advantages


14
Converges fast, if it converges
Requires two guesses that do not need to
bracket the root
http://numericalmethods.eng.usf.edu
Drawbacks
2
2
1
f ( x)
f ( x)
0
0
f ( x)
1
2
2
10
5
 10
0
5
x x guess 1 x guess 2
f(x)
p rev . gu ess
n ew g uess
10
10
f x   Sinx   0
Division by zero
15
http://numericalmethods.eng.usf.edu
Drawbacks (continued)
2
2
1
f ( x)
f ( x)
0
f ( x)
0
secant( x)
f ( x)
1
2
2
10
5
 10
0
5
10
x x 0  x 1' x x 1
f(x)
x'1 , (fi rst gu ess)
x0 , (p rev io us gu ess)
Secant li ne
x1 , (n ew g uess)
10
f x   Sinx  0
Root Jumping
16
http://numericalmethods.eng.usf.edu
Additional Resources
For all resources on this topic such as digital audiovisual
lectures, primers, textbook chapters, multiple-choice
tests, worksheets in MATLAB, MATHEMATICA, MathCad
and MAPLE, blogs, related physical problems, please
visit
http://numericalmethods.eng.usf.edu/topics/secant_me
thod.html
THE END
http://numericalmethods.eng.usf.edu