Uploaded by semeya6041

Lecture 6

advertisement
SECANT METHOD
 SECANT METHOD
 EXAMPLES
Read section 6.3 in the textbook
1
NEWTON’S METHOD (REVIEW)
Assumptions : f ( x), f ' ( x), x0 are available,
f ' ( x0 )  0
Newton' s Method new estimate :
f ( xi )
xi 1  xi 
f ' ( xi )
Problem :
f ' ( xi ) is difficult to obtain analytically.
2
SECANT METHOD
if xi and xi 1 are two initial points :
f ( xi 1 )  f ( xi )
f ' ( xi ) 
( xi 1  xi )
f ( xi )
xi 1  xi 
f ( xi 1 )  f ( xi )
( xi 1  xi )
xi 1 
( xi 1  xi )
xi  f ( xi )
f ( xi 1 )  f ( xi )
3
SECANT METHOD
Assumptions :
Two initial points xi and xi 1
such that f ( xi )  f ( xi 1 )
New estimate (Secant Method) :
( xi 1  xi )
xi 1  xi  f ( xi )
f ( xi 1 )  f ( xi )
4
SECANT METHOD - FLOWCHART
x0 , x1 , i  1
xi 1  xi  f ( xi )
( xi 1  xi )
;
f ( xi 1 )  f ( xi )
i  i 1
NO
xi 1  xi

xi 1
Yes
Stop
5
MODIFIED SECANT METHOD
In this modified Secant method, only one initial guess is needed :
f ( xi   xi )  f ( xi )
f ' ( xi ) 
 xi
 xi f ( xi )
xi 1  xi 
f ( xi   xi )  f ( xi )
Problem : How to select  ?
If not selected properly, the method may diverge .
6
EXAMPLE
50
Find the roots of :
f ( x)  x 5  x 3  3
40
30
20
Initial points x0  1 and x1  1.1
10
0
-10
with error  0.001
-20
-30
-40
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
7
EXAMPLE
i
x(i-1)
f(x(i-1))
x(i)
f(x(i))
X(i+1)
x(i+1)−x(i)
∗ 100
x(i+1)
1
-1.0000
1.0000
-1.1000
0.0585
-1.1062
0.5616
2
-1.1000
0.0585
-1.1062
-0.0102
-1.1053
0.0833
3
-1.1062
-0.0102
-1.1053
0.0001
-1.1053
0.0000
8
COMPARISON OF ROOT FINDING
METHODS
 ADVANTAGES/DISADVANTAGES
 EXAMPLES
9
SUMMARY
Method
Pros
Cons
Bisection
- Easy, Reliable, Convergent
- No knowledge of derivative is
needed
- Slow
- Needs an interval [a,b]
containing the root, i.e.,
f(a)f(b)<0
Newton
- Fast (if near the root)
- May diverge
- Needs derivative and an
initial guess x0 such that
f’(x0) is nonzero
Secant
- Fast (slower than Newton)
- No knowledge of derivative is
needed
- May diverge
- Needs two initial points
guess x0, x1 such that
f(x0)- f(x1) is nonzero
10
EXAMPLE
Use Secant method to find the root of :
f ( x)  x 6  x  1
Two initial points x0  1 and x1  1.5
( xi  xi 1 )
xi 1  xi  f ( xi )
f ( xi )  f ( xi 1 )
11
SOLUTION
_______________________________
k
xk
f(xk)
_______________________________
0
1.0000 -1.0000
1 1.5000 8.8906
2 1.0506 -0.7062
3 1.0836 -0.4645
4 1.1472 0.1321
5 1.1331 -0.0165
6 1.1347 -0.0005
12
EXAMPLE
Use Newton' s Method to find a root of :
f ( x)  x 3  x  1
Use the initial point : x0  1.
Stop after three iterations, or
if   0.001, or
if
f ( xk )  0.0001.
13
FIVE ITERATIONS OF THE SOLUTION
k
xk
f(xk)
f’(xk)
ERROR
______________________________________
0
1.0000
-1.0000 2.0000
1
1.5000
0.8750
5.7500
33.33
2
1.3478
0.1007
4.4499
11.29
3
1.3252
0.0021
4.2685
1.71
4
1.3247
0.0000
4.2646
0.0364
5
1.3247
0.0000
4.2646
0.0000
14
EXAMPLE
Use Newton' s Method to find a root of :
f ( x)  e  x  x
Use the initial point : x0  1.
Stop after three iterations, or
if   0.001, or
if
f ( xk )  0.0001.
15
EXAMPLE
Use Newton' s Method to find a root of :
f ( x )  e  x  x,
xk
1.0000
0.5379
0.5670
0.5671
f ' ( x )  e  x  1
f ( xk )
f ' ( xk )
- 0.6321
0.0461
0.0002
0.0000
- 1.3679
- 1.5840
- 1.5672
- 1.5671

85.91
5.133
0.0276
16
EXAMPLE
Estimates of the root of:
0.60000000000000
x-cos(x)=0.
Initial guess
0.74401731944598
1 correct digit
0.73909047688624
4 correct digits
0.73908513322147
10 correct digits
0.73908513321516
14 correct digits
17
EXAMPLE
In estimating the root of: x-cos(x)=0, to get 13 correct digits:
 4 iterations of Newton (x0=0.8)
 46 iterations of Bisection method (initial
𝜀𝑠 = 0.5 ∗ 102−𝑛 %
interval [0.6, 0.8])
 6 iterations of Secant method
( x0=0.6, x1=0.8)
18
ROOT FINDING IN MATLAB
Matlab has two commonly used functions for root finding:
1. roots, finds the n complex roots of an nth degree polynomial
Example:
find the roots of the cubic equation x^ 3 − 3x^ 2 + 4x − 2 = 0,
>> p=[1 -3 4 -2];
>> r=roots(p)
r=
1.0000 + 1.0000i
1.0000 - 1.0000i
1.0000 + 0.0000i
ROOT FINDING IN MATLAB
2. fzero.m, finds a real root of a nonlinear function.
r = fzero(f,x0)
x0 is either an initial guess for the root, or a two-dimensional vector whose
components bracket the root.
Example:
>> f=@(x)x-exp(-0.5*x);
>> r = fzero(f,1)
r=
0.7035
Download