Revew of Taylor Seres Read Secton 1.2 1
Power Seres A power seres about c s an nfnte seres of the form k = 0 k a ( x c) = a + a ( x c) + a ( x c) + a ( x c) k 2 3 0 1 2 3 + In many cases, c = 0, and the seres takes the smpler form k = 0 a k 2 3 k x = a0 + a1x+ a2x + a3x + Specal power seres of our nterest are Taylor seres. 2
Taylor Seres The Taylor seres of a functon f( x) about the pont c ( k ) f ( c) s the power seres k ( x c). k! k = 0 k = 0 f ( c) f ( c) f( x) f( c) f ( c)( x c) ( x c) ( x c) 2! 3! ( k ) f ( c) ( ) k = x c k! 2 3 + + + + If f( x) equals ts Taylor seres n an nterval I contanng c, f( x) s sad to be analytc n I. 3
x Taylor Seres of e about c= 0 ( k ) f ( c) k f( x) ( x c). k! k = 0 d e = e f c = e = e dx x x ( k) c 0, so ( ) 1. = e x k = 0 k x. k! 4
Some Famlar Taylor Seres 2 3 k x x x x e = 1 + x+ + + = ( x < ) 2! 3! k! k = 0 3 5 7 2k + 1 x x x k x sn x = x + + = ( 1) ( x < ) 3! 5! 7! (2k + 1)! k = 0 2 3 4 k x x x k 1 x ln(1 + x) = x + + = ( 1) ( x < 1) 2 3 4 k k = 0 5
e x 2 3 4 5 6 x x x x x = 1+ x+ + + + + + 2! 3! 4! 5! 6! e x 2 3 4 5 6 x x x x x 1+ x+ + + + + 2! 3! 4! 5! 6! What's the error n ths approxmaton? 6
Taylor's Theorem If a functon s dfferentable to the ( n + 1)th order n a closed nterval I = [ a, b], then for any c and x n I, n ( k ) f ( c) k f( x) = ( x c) + k! k = 0 E n + 1 where the error term ( n+ 1) f ( μ) En+ 1 = ( x c) ( n + 1)! for some pont between x and c. n+ 1 7
Taylor's Theorem for f ( c+ h) Let h= x c, then x= c+ h, and Taylor's Theorem becomes: n ( k ) f ( c) k f( c+ h) = h + E k! k = 0 where the error term n+ 1 E n+ 1 = ( n+ 1) f ( μ) ( n + 1)! h n+ 1 for some pont between c and c+ h. 8
Root Fndng Read Chapter 3 9
Roots and Zeros Equaton: f( x) = 0 A number r for whch f( r) = 0 s called a root of the equaton f( x) = 0 a zero of the functon f 2 Example: the equaton x 2x 3 = 0 has two roots, 2 1 and 3; the polynomal 2 3 has two x= x= x x zeros, x= 1 and x= 3. 10
Bsecton Method Assume f s contnuous. If f( a) and f( b) have dfferent sgns, then there s a root n [ a, b]. The bsecton method s smlar to the bnary sear ch. 11
Bsecton Method Input: functon f, nterval [ a, b] where f( a) f( b) < 0, ε. Algorthm: 1. Compute the mdpont c= ( a+ b) / 2; 2. f f( c) = 0 then return( c); /* unlkely */ 3. f sgn( f( a)) sgn( f( c)) Recurse on I : = [ a, c] else /* sgn( f( c)) sgn( f( b)) */ Recurse on I : = [ c, b] endf I 4. Repeat untl < ε; then return the mdpont of I. 2 12
Bsecton Method Bsecton( f, a, b, ε, k) /* Precondton: sgn( f( a)) sgn( f( b)) */ /* k = max # of remanng teratons */ 1. c ( a+ b) / 2 2. f f( c) = 0 then return( c); 3. f ( ( b a) /2 < ε or k < 1) then return( c); 4. f sgn( f( a)) sgn( f( c)) then 5. Bsecton( f, a, c, ε, k 1); 6. else /* sgn( f( c)) sgn( f( b)) */ 7. Bsecton( f, c, b, ε, k 1); 8. endf 13
Convergence of Bsecton Method How many teratons are needed? Let [ ab, ] = [ a, b] be the ntal nterval. 0 0 Let [ a, b] be the nterval of the th recursve call. Length of nterval [ a, b]: b a = b 2 #teratons (recursve calls) needed: a 1 b a ( b a) < ε 2 > 2 2 2ε ( b a) > log2 = log 2( b a) log22ε 2ε 14
Convergence of Bsecton Method [ a0, b0] = [ a, b]: the ntal nterval. [ a, b]: the nterval of the th recursve call. Mdponts of these ntervals c0, c1, c2, form a sequence of approxmatons to the root r. Let e = r c. c0 = ( a0 + b0) / 2 e0 ( b a) 2 c1 = ( a1+ b1)/2 e1 ( b a) 2 c = ( a + b)/2 e ( b a) 2 ( c c c ) How fast does the sequence,,, converge to r? 0 1 2 Approxmately 1 bt per teraton. 2 + 1 15
Regula Fals: Improved Bsecton Method Choose c to be the pont where the secant lne between ( a, f( a)) and ( b, f( b)) ntersects the x axs. Regula Fals often converges faster than bsecton. c 16
The equaton of secant lne: y f( b) f( a) f( b) = x b a b bf ( a) af ( b) When y = 0, x=, whch s c. f( a) f( b) c 17
Newton's Method Approxmate f( x) by a straght lne l( x), and use the root of lx ( ) as an approxmaton to the root of f( x). lx ( ) : a lne tangent to the functon at a current guess. 18
Newton's Method The slope of the tangent lne s the dervatve f ( x0). So: y = f ( x0)( x x0) + f( x0) f( x ) 0 When y = 0, x= x0. f ( x0) Ths gves us a sequence: x f( x0) = x f ( x ) 1 0 0 x f( x1) = x f ( x ) 2 1 1 x = x 3 2 f( x2) f( x ) x+ 1 = x f ( x ) f ( x ) 2 19
Newton's Method: Example What s f ( x) : 3 2 Fnd a zero for f( x) = x + 2x 11x 12 So f x = x + x 2 ( ) 3 4 11 3 2 f( x) x + 2x 11x 12 + 1 = = 2 f ( x) 3x + 4x 11 x x x Start wth x 0 = 30 Does ths method always converge? 20
Newton's Method: Bad Functons 21
Newton's Method: Convergence Doesn't always converge. Assume: f, f, f are contnuous n a neghborhood of r (the root) and f ( r) 0. The sequence ( x0, x1, x2, ) converges f x0 s close enough to r. Converges quadratcally : r x c r x + 1 2 or e + 1 ce 2 where c s a postve constant. 22
Quadratc Convergence The error terms satsfy: e 1 Example: Suppose c= 1, and e0 2. 1 e0 2 2 e1 2 4 e2 2 8 e3 2 16 e4 2 The number of correct dgts doubles wth each teraton. Fve or sx teratons are often suffcent to yeld full machne precson. + 1 ce 2 23
Newton's Method: Remarks We must be able to evaluate f ( x), whch s not always the case. Does not guarantee convergence. But t s very fast, f the startng pont s close enough to the root. 24
Secant Method As n Newton's method, approxmate the functon wth a lne, but ths tme a secant lne. Two startng ponts: x and x. 0 1 25
Secant Method Let the ntersecton pont be ( x f( x1) f( x0) 0 f( x1) = x x x x 1 0 2 1 2,0). Equate the slopes: Rearrange: x = x f ( x ) 2 1 1 x x 1 0 f( x ) f( x ) 1 0 Do the same thng for x usng x and x. 3 1 2 In general: x = x f( x ) + 1 x 1 f( x ) f ( x ) x 1 26
Secant Method vs Newton's Method Secant method s smlar to Newton's method except that f ( x ) s approxmated by f ( x ) f( x) f( x 1) x x So how does t compare to Newton's method? How many functon evaluatons are needed per teraton? Wll t converge? How about speed of convergence? e 1 ce α +, α 1.62, the golden rato. Not qute as fast as Newton's method but stll superlnear and much faster than bsecton. But f you consder number of evaluatons t could be faster than Newton's. 1 27
Root Fndng Comparson Bsecton Method Always converges, but does so slowly, Needs two startng values on opposte sdes of the root. Newton's Method May not converge, but converges quckly near the root. Needs two functon evaluatons per teraton. Needs to be able to evaluate f. Secant Method May not converge, but converges quckly near the root. Needs one functon evaluaton per teraton. Doesn't need f. 28
Hybrd Methods Most popular Combne Bsecton wth Newton's or Secant. Apply Bsecton for a few steps and then swtch to Newton or Secant. 29
Root Fndng wth Matlab Matlab has a functon gven functon. fzer o that returns a root of a 30
Defne a Functon The followng Matlab scrpt defnes a functon f( x) = x x + sn( x) + 7. 5 3 Store the scrpt n a fle named f.m functon y = f(x) % defne a functon named "f" y = x^5 - x^3 + sn(x) + 7; 31
Plot the Functon lnspace(a,b) defnes a 100 equally-spaced ponts nterval [a,b]. lnspace(a,b) draw the dagram. Try plot(x,y,'r*'), plot(x,y,'g+'). Use help plot to get more nformaton. x = lnspace(-p, p); % an array of 100 equally-spaced ponts n [-p,p] for = 1:100 y() = f(x()) end plot(x,y) 32
Fnd the Root fzero('fname', [a b]) tres to fnd a zero of the functon fname n the nterval [a,b]. fzero('fname', a) tres to fnd a zero of the functon fname near a. x = lnspace(-p,p); for = 1:100 y() = f(x()); end; root = fzero('f',[-2 2]); plot(x,y, root, 0, 'ro'); root, f_val_at_root = f(root) 33