Download presentation
Presentation is loading. Please wait.
1
Sec:4.1 THE TAYLOR SERIES
2
Sec:4.1 THE TAYLOR SERIES Taylor’s theorem
states that any smooth function can be approximated as a polynomial. Taylor series ( center is a ) If the function f and its first n + 1 derivatives are continuous on an interval containing a and x, there exists a point ξ between a and x such that the reminder Maclaurin series ( center is 0 ) ξ between 0 and x
3
Sec:4.1 THE TAYLOR SERIES Example: Taylor series ( center is a )
Example: Let f (x) = cos x and a = 0. Determine (a) the second order approximation for f about a; and (b) Use (a) to approximate cos(0.01) f(x) = cos x, f'(x) = −sin x, f’’(x) = −cos x, f’’’(x) = sin x, f’’’’(x) = cos x, f(0) = 1, f'(0) = 0, f’’(0) = −1, f’’’(0) = 0, f’’’’(0) = 1, 𝑓 𝑥 =𝑐𝑜𝑠𝑥 syms x taylor(cos(x),x,0,'order',3) 1 - x^2/2 p 𝒙 =𝟏− 𝟏 𝟐 𝒙 𝟐 ezplot('cos(x)',[-pi,pi]); hold on ezplot('1-x.^2/2',[-pi,pi]); hold off grid on
4
Sec:4.1 THE TAYLOR SERIES Example:
Let f (x) = cos x and a = 0. Determine (a) the second order approximation for f about a; and (b) Use (a) to approximate cos(0.01) How accurate this approximation: exact approximation Hence the approximation matches at least the first five digits of the exact
5
Sec:4.1 THE TAYLOR SERIES Example:
Let f (x) = cos x and a = 0. Determine (a) the second order approximation for f about a; and (b) Use (a) to approximate cos(0.01) This example illustrates the two objectives of numerical analysis: Find an approximation to the solution of a given problem. (ii) Determine a bound for the accuracy of the approximation
6
Sec:4.1 THE TAYLOR SERIES Example:
Why: we want to approximate a function by a polynomial. Example: Let f (x) = cos x and a = 0. Determine (a) the third order approximation for f about a; and (b) Use (a) to approximate integrate both sides exact approximation
7
Sec:4.1 THE TAYLOR SERIES Taylor’s theorem
states that any smooth function can be approximated as a polynomial. Taylor series ( center is a ) there exists a point ξ between a and x such that Another expression for the Reminder
8
Sec:4.1 THE TAYLOR SERIES Taylor series ( center is a )
It is often convenient to simplify the Taylor series by defining a step size h = xi+1 − xi and expressing above as Taylor series ( center is a )
9
Sec:4.1 THE TAYLOR SERIES 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊
𝑓 𝑥 𝑖+1 =𝑓 𝑥 𝑖 + 𝑓′( 𝑥 𝑖 ) 1! ℎ+ 𝑓 2 ( 𝑥 𝑖 ) 2! ℎ 2 +…+ 𝑓 𝑛 𝑥 𝑖 𝑛! ℎ 𝑛 + 𝑹 𝒏 Taylor series 𝑓 𝑥 𝑖+1 =𝑓 𝑥 𝑖 + 𝑓 ′ 𝑥 𝑖 1! ( 𝑥 𝑖+1 − 𝑥 𝑖 )+ 𝑓 2 ( 𝑥 𝑖 ) 2! ( 𝑥 𝑖+1 − 𝑥 𝑖 ) 2 +…+ 𝑓 𝑛 𝑥 𝑖 𝑛! ( 𝑥 𝑖+1 − 𝑥 𝑖 ) 𝑛 + 𝑹 𝒏 First-order approximation forward finite difference 𝑓 𝑥 𝑖+1 =𝑓 𝑥 𝑖 + 𝑓 ′ 𝑥 𝑖 1! ( 𝑥 𝑖+1 − 𝑥 𝑖 )+ 𝑓 2 (𝜉) 2! ( 𝑥 𝑖+1 − 𝑥 𝑖 ) 2 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 Move the first term to left side and divid by h 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 − 𝒇 ′ 𝒙 𝒊 = 𝒇 𝟐 (𝝃) 𝟐! 𝒉 Truncation error Approximation to the derivative
10
Sec:4.1 THE TAYLOR SERIES forward finite difference 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 − 𝒇 ′ 𝒙 𝒊 = 𝒇 𝟐 (𝝃) 𝟐! 𝒉 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 SIMILAR TO PROBLEM 4.5/p105: 𝒙 𝒊 =2 𝒙 𝒊+𝟏 =2.2 Use forward difference approximations to estimate the first derivative of the function 𝒇 (𝒙) = 𝟐𝟓 𝒙 𝟑 − 𝟔 𝒙 𝟐 + 𝟕𝒙 Evaluate the derivative at x = 2 using a step size of h = 0.2, 0.1, Compare your results with the true value of the derivative. Interpret your results on the basis of the remainder term of the Taylor series expansion. 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 h = 0.2 𝒇 ′ 𝟐 ≈ 𝒇 𝟐.𝟐 −𝒇 𝟐 𝟎.𝟐 = 𝟐𝟓𝟐.𝟓𝟔−𝟏𝟗𝟎 𝟎.𝟐 =𝟑𝟏𝟐.𝟖 h = 0.1 𝒇 ′ 𝟐 ≈ 𝒇 𝟐.𝟏 −𝒇 𝟐 𝟎.𝟏 =𝟐𝟗𝟕.𝟔𝟓 h = 0.001 𝒇 ′ 𝟐 ≈ 𝒇 𝟐.𝟎𝟎𝟏 −𝒇 𝟐 𝟎.𝟎𝟎𝟏 =𝟐𝟖𝟑.𝟏𝟒𝟒𝟎𝟐𝟓 𝒇 ′ 𝟐 =𝟐𝟖𝟑
11
Sec:4.1 THE TAYLOR SERIES first finite divided difference 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 − 𝒇 ′ 𝒙 𝒊 = 𝒇 𝟐 (𝝃) 𝟐! 𝒉 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 SIMILAR TO PROBLEM 4.5/p105: 𝒙 𝒊 =2 𝒙 𝒊+𝟏 =2.2 Use forward difference approximations to estimate the first derivative of the function 𝒇 (𝒙) = 𝟐𝟓 𝒙 𝟑 − 𝟔 𝒙 𝟐 + 𝟕𝒙 Evaluate the derivative at x = 2 using a step size of h = 0.2, 0.1, Compare your results with the true value of the derivative. Interpret your results on the basis of the remainder term of the Taylor series expansion. h = 0.001 𝒇 ′ 𝟐 ≈ 𝒇 𝟐.𝟎𝟎𝟏 −𝒇 𝟐 𝟎.𝟎𝟎𝟏 =𝟐𝟖𝟑.𝟏𝟒𝟒𝟎𝟐𝟓 𝒇 ′ 𝟐 =𝟐𝟖𝟑 Error = 0.𝟏𝟒𝟒𝟎𝟐𝟓 𝒇 𝟐 (𝝃) 𝟐! 𝒉 𝒇 (𝟐) (𝒙) =𝟏𝟓𝟎𝒙−𝟏𝟐 𝒇 𝟐 (𝝃) 𝟐! 𝒉= 75ξ−6 ∗(0.001) ≤ 75∗2.001−6 ∗(0.001) ≤
12
Sec:4.1 THE TAYLOR SERIES 𝒂 𝒙 𝒙 𝒊+𝟏 𝒙 𝒊−𝟏 𝒙 𝒊
Taylor series ( center is a ) 𝒙 𝒂 𝒙 𝒊−𝟏 𝒙 𝒊+𝟏 𝒙 𝒊 Taylor series 𝑹 𝒏 = (−1) 𝑛+1 𝑓 𝑛+1 𝑥 𝑖 (𝑛+1)! ℎ 𝑛+1 𝑓 𝑥 𝑖−1 =𝑓 𝑥 𝑖 − 𝑓 ′ 𝑥 𝑖 1! ℎ+ 𝑓 𝑥 𝑖 2! ℎ 2 +…+ (−1) 𝑛 𝑓 𝑛 𝑥 𝑖 𝑛! ℎ 𝑛 + 𝑹 𝒏
13
Sec:4.1 THE TAYLOR SERIES 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊 −𝒇 𝒙 𝒊−𝟏 𝒙 𝒊 − 𝒙 𝒊−𝟏
𝑹 𝒏 = (−1) 𝑛+1 𝑓 𝑛+1 𝑥 𝑖 (𝑛+1)! ℎ 𝑛+1 𝑓 𝑥 𝑖−1 =𝑓 𝑥 𝑖 − 𝑓 ′ 𝑥 𝑖 1! ℎ+ 𝑓 𝑥 𝑖 2! ℎ 2 +…+ (−1) 𝑛 𝑓 𝑛 𝑥 𝑖 𝑛! ℎ 𝑛 + 𝑹 𝒏 First-order approximation backward finite difference 𝑓 𝑥 𝑖−1 =𝑓 𝑥 𝑖 − 𝑓 ′ 𝑥 𝑖 1! ( 𝑥 𝑖 − 𝑥 𝑖−1 )+ 𝑓 2 (𝜉) 2! ℎ 2 𝒇 ′ 𝒙 𝒊 ≈ 𝒇 𝒙 𝒊 −𝒇 𝒙 𝒊−𝟏 𝒙 𝒊 − 𝒙 𝒊−𝟏 Move the first term to left side and divid by h 𝒇 𝒙 𝒊 −𝒇 𝒙 𝒊−𝟏 𝒙 𝒊 − 𝒙 𝒊−𝟏 − 𝒇 ′ 𝒙 𝒊 =− 𝒇 𝟐 (𝝃) 𝟐! 𝒉 Truncation error Approximation to the derivative
14
Sec:4.1 THE TAYLOR SERIES forward finite difference backward finite difference 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊 𝒙 𝒊+𝟏 − 𝒙 𝒊 − 𝒇 ′ 𝒙 𝒊 = 𝒇 𝟐 (𝝃) 𝟐! 𝒉 𝒇 𝒙 𝒊 −𝒇 𝒙 𝒊−𝟏 𝒙 𝒊 − 𝒙 𝒊−𝟏 − 𝒇 ′ 𝒙 𝒊 =− 𝒇 𝟐 (𝝃) 𝟐! 𝒉 Centered finite difference 𝒇 𝒙 𝒊+𝟏 −𝒇 𝒙 𝒊−𝟏 𝟐𝒉 − 𝒇 ′ 𝒙 𝒊 =𝑶( 𝒉 𝟐 ) Notice that the truncation error is of the order of ℎ 2 in contrast to the forward and backward approximations that were of the order of h. Consequently, the Taylor series analysis yields the practical information that the centered difference is a more accurate representation of the derivative
15
Sec:4.1 THE TAYLOR SERIES SIMILAR TO PROBLEM 4.5/p105: Use forward and backward difference approximations of O(h) and a centered difference approximation of O(h2)to estimate the first derivative of the function 𝒇 (𝒙) = 𝟐𝟓 𝒙 𝟑 − 𝟔 𝒙 𝟐 + 𝟕𝒙 Evaluate the derivative at x = 2 using a step size of h = 0.1, 0.01, , , Compare your results with the true value of the derivative. 1.0e+02 * h backward difference forward difference centered difference 0.1 0.01 0.001 0.0001 back diff error forward diff error centered diff error 0.1 0.01 0.001 0.0001 Error Table
16
Sec:4.1 THE TAYLOR SERIES format short fun = @(x) 25*x^3 - 6*x^2+7*x;
dfun 75*x^2 - 12*x + 7; x=2; exact = dfun(2); h_vec=[ ]; for i=1:5 h = h_vec(i); [bd,fd,cd] = num_diff(fun,x,h); bd_vec(i) = bd; fd_vec(i) = fd; cd_vec(i) = cd; end format long res1 = [ bd_vec' fd_vec' cd_vec'] res2 = [h_vec' bd_vec' fd_vec' cd_vec'] err = [bd_vec' fd_vec' cd_vec']-exact; err_res = [h_vec' err] function [bd,fd,cd] = num_diff(f,x,h) xi = x; xip1 = xi+h; xim1 = xi-h; bd = (f(xi) - f(xim1))/h; fd = (f(xip1) - f(xi) )/h; cd = (f(xip1) - f(xim1))/(2*h); end fun 25*x^3 - 6*x^2+7*x; dfun 75*x^2 - 12*x + 7; h=0.2; x=2; [bd,fd,cd] = num_diff(fun,x,h) dfun(2)
17
Sec:4.1 THE TAYLOR SERIES 𝒇 𝟐 (𝒙) Second Derivative Approximation
𝒇 𝟐 (𝒙) Second Derivative Approximation forward finite difference 𝒙 𝒊−𝟏 𝒙 𝒊 𝒙 𝒊+𝟏 𝒙 𝒊+𝟐 𝒙 𝒊−𝟐 𝒇 𝒙 𝒊+𝟐 −𝟐𝒇 𝒙 𝒊+𝟏 +𝒇 𝒙 𝒊 𝒉 𝟐 − 𝒇 ′′ 𝒙 𝒊 =𝑶(𝒉) backward finite difference 𝒙 𝒊−𝟏 𝒙 𝒊 𝒙 𝒊+𝟏 𝒙 𝒊+𝟐 𝒙 𝒊−𝟐 𝒇 𝒙 𝒊 −𝟐𝒇 𝒙 𝒊−𝟏 +𝒇 𝒙 𝒊−𝟐 𝒉 𝟐 − 𝒇 ′′ 𝒙 𝒊 =𝑶(𝒉) Centered finite difference 𝒙 𝒊−𝟏 𝒙 𝒊 𝒙 𝒊+𝟏 𝒙 𝒊+𝟐 𝒙 𝒊−𝟐 𝒇 𝒙 𝒊+𝟏 −𝟐𝒇 𝒙 𝒊 +𝒇 𝒙 𝒊−𝟏 𝒉 𝟐 − 𝒇 ′′ 𝒙 𝒊 =𝑶( 𝒉 𝟐 )
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.