Problem. Produce the linear and quadratic Taylor polynomials for the following functions: (a) f(x) = e cos(x), a = (b) log( + e x ), a = The general formula for any Taylor Polynomial is as follows: (a) Thus, for the linear and quadratic Taylor Polynomials P n (x) = f n (a) (x a) n n! f(x) = e cos(x) f() = e f (x) = sin(x)e cos(x) f () = f (x) = sin(x)( sin(x)e cos(x) ) cos(x)e cos(x) f () = e P (x) = e P (x) = e e x Plot of Taylor Polynomials for f(x) = e cos(x) (b) Thus, for the linear and quadratic Taylor Polynomials f(x) = log( + e x ) f() = log() f (x) = (+e x ) ex f () = f (x) = e x (+e x ) ex (+e x ) f () = 4 P (x) = log() + x P (x) = log() + x + 4! x = log() + x + 8 x Plot of Taylor Polynomials for f(x) = log( + e x )
Code for plots %Code for graphing f(x)=e^cos(x) and the linear and quadraic Taylor %Polynomials of f(x) figure() g=@(t)exp().^(cos(t)); x=linspace(-,,); y=g(x); clf plot(x,y, b-+ ); hold on %Linear polynomial about x= p=@(t)exp()*t.^; y=p(x) plot(x,y, r-. ); %Quadratic Polynomial about x= p=@(t)exp()-exp()/*t.^; y=p(x); plot(x,y, k--* ) title ( Linear and Quadratic Taylor Approximation to e^cos(x) ) legend( e^cos(x), p_, p_ ) xlabel( x ) ylabel( y ) %Code for graphing f(x)=log(+e^x) and the linear and quadracti Taylor %Polynomials of f(x) figure() f=@(t)log(+exp().^t); y=f(x); clf plot(x,y, b-+ ) hold on %Linear Polynomial about x= p=@(t)log()+.5*t; y=p(x); plot(x,y, r-. ); %Quadratic Polynomial about x=
p=@(t)log()+.5*t+(/8)*t.^; y=p(x); plot(x,y, k--* ) title ( Linear and Quadratic Taylor Approximation to log(+e^x) ) legend( log(+e^x), p_, p_ ) xlabel( x ) ylabel( y ) Problem. Produce a general form for the degree n Taylor Polynomials for the following functions, using a = as the point of expansion (a)f(x) = /(x ) (b)f(x) = ( + x) /3 (a) f(x) = ( x) f() = f (x) = ( x) f () = f (x) = ( x) 3 f () = f (x) = 6 ( x) 4 f () = 6 Thus, inputting into the general equation for a Taylor polynomial gives: Thus, in the general form (b) P 3 (x) = + x + x! P n (x) = + 6x3 n i= = + x + x + x 3 x i f(x) = ( + x) /3 f() = f (x) = 3 ( + x) 3 f () = 3 f (x) = 3 ( 3 )( = x) 3 f () = 3 ( 3 ) f (x) = 3 ( 3 )( 3 )( = x) 3 f () = 3 ( 3 )( 3 ) Thus, using the general form for a Taylor polynomial gives: P 3 (x) = + 3 x + 3 ( 3 ) x +! However, using the notation for binomial coefficients gives ( ) 3 = n 3 ( 3 )( 3 ) 3 ( 3 )( 3 )... ( 3 n + ) n! Thus, the general form for the Taylor polynomial may be given as P n (x) = n i= ( ) 3 x i i Problem 3. Compare f(x) = sin(x) with its Taylor polynomials of degrees,3, and 5. x 3 f(x) = sin(x) f() = f (x) = cos(x) f () = f (x) = sin(x) f () = f (x) = cos(x) f () = 3
Thus, using the general form of the Taylor polynomial gives the following: P (x) = x P 3 (x) = x x3 P 5 (x) = x x3 + x5 5! Table for Taylor polynomial error x sin(x) p_(x) sin(x)-p_(x) p_3(x) sin(x)-p_3(x) p_5(x) sin(x)-p_5(x) -. -.8447 -..5859 -.8333333.8377 -.846667.957 -.9 -.783369 -.9.6673 -.7785.4869 -.78347.938 -.8 -.77356 -.8.86439 -.746667.6894 -.773973.4 -.7 -.64477 -.7.55783 -.648333.3844 -.644339.6 -.6 -.564645 -.6.353575 -.564.645 -.564648.55 -.5 -.479455 -.5.5745 -.479667.589 -.47947.5 -.4 -.389483 -.4.587 -.3893333.85 -.389487.3 -.3 -.955 -.3.44798 -.955. -.9553. -. -.986693 -..337 -.986667.7 -.986693. -. -.998334 -..666 -.998333. -.998334...........998334..666.998333..998334...986693..337.986667.7.986693..3.955.3.44798.955..9553..4.389483.4.587.3893333.85.389487.3.5.479455.5.5745.479667.589.47947.5.6.564645.6.353575.564.645.564648.55.7.64477.7.55783.648333.3844.644339.6.8.77356.8.86439.746667.6894.773973.4.9.783369.9.6673.7785.4869.78347.938..8447..5859.8333333.8377.846667.957 Code for generating table %Code for finding error in Taylor Polynomials g=@(t)sin(t); x=linspace(-,,); y=g(x); %First Degree Taylor polynomial about x= p=@(t)t; y=p(x); %Third Degree Taylor Polynomial about x= p3=@(t)t-t.^3/factorial(3); y3=p3(x); %Fifth Degree Taylor Polynomial about x= p5=@(t)t-t.^3/factorial(3)+t.^5/factorial(5); y5=p5(x); %Calculating Error in Taylor approximation and actual function err=abs(y-y); err3=abs(y-y3); err5=abs(y-y5); %Code for generating table fprintf( %s %s %s %5s %s %5s %s %5s\n, x, sin(x), p_(x), sin(x)-p_(x), p_3(x), sin(x)-p_3(x), p_5(x), sin(x)-p_5(x) ), for i=: 4
fprintf( %.7f %.7f %.7f %5.7f %.7f %5.7f %.7f %5.7f\n, x(i),y(i),y(i),err(i), y3(i),err3(i),y5(i),err5(i)) end Problem 4. Explain why the quotients are undefined for x =, then use Taylor polynomials in the numerator of each quotient to determine the natural definition of g(). (a) g(x) = log( + x) x The function is undefined when x = because of division by zero. However using a Taylor polynomial in the numerator, one can define a natural definition for g(). Let n(x) = log( + x). Thus, n(x) = log( + x) n() = log() = n (x) = (+x) n () = n (x) = (+x) n () = n (x) = (+x) n () = 3 Thus, using the general formula for the Taylor polynomial gives the following Thus, in general P n (x) = i= P 3 (x) = x x! + x3 Then, substituting the Taylor polynomial in the numerator gives Expanding the sum shows Then, g() = as a natural definition. n ( ) i+ x i n ( ) i+ x i = x i i g(x) x n ( ) i+ x i i= i x = i= n ( ) i+ x i i= g(x) x + x 3 + i (b) g(x) = log( x) + xex/ x 3 This function is undefined at x = because of division by zero. However, by approximating the numerator with a Taylor polynomial, one can naturally define g(). A Taylor polynomial will be created for each addition term in the numerator, and then the two Taylor polynomials will be added together to create the complete Taylor polynomial for the numerator. This begin as follows, Thus, the Taylor polynomial may be written as, n (x) = log( x) n () = n (x) = ( x) n () = n (x) = ( x) n () = n (x) = 3 ( x n () = P n, (x) = x x x3 3 + For the second part of the numerator, let n (x) = xe x/. The Taylor polynomial for this function can be found by beginning with the well known Taylor polynomial for e x. P ex,n(x) = + x + x! + 5
Thus, to find the Taylor polynomial for e x/ simply replace x with x/ as follows: P e x/,n(x) = + x + ( x )! + = + x + x 4! + Lastly, to obtain the Taylor polynomial for xe x/ simply multiply the Taylor polynomial for e x/ by x, as follows, P n, (x) = x[ + x + x 4! + ] = x + x + x3 4! + Then the Taylor polynomial for the entire numerator may be found by adding P n, to P n, as follows, P n (x) = x + x + x3 x + + x 4! x3 3 + = x3 ( 8 3 ) + Thus, replacing the numerator with the new Taylor polynomial yields Finally, a natural definition for g() can be found as follows. g(x) P n(x) x 3 = x3 ( 8 3 ) + x4 x 3 = ( 8 3 ) + x g() = ( 8 3 ) = 5 4 Problem 5. Find the linear and quadratic Taylor polynomials for f(x) = 3 x about a = 8. f(x) = x /3 f(8) = f (x) = 3 x 3 f (8) = f (x) = 9 x 5 9 f (8) = 44 f (x) = 7 x 8 3 f (8) = 5 3456 Then, using the general formula for a Taylor polynomial gives the linear and quadratic Taylor polynomials to be, (x 8) P (x) = + (x 8) P 3 (x) = + (x 8) 44 The general formula for finding the error in a Taylor approximation can then be found by the following where a c x x Thus finding the error in the linear Taylor polynomial R n (x) = f n+ (c x ) (x a)n+ (n + )! f n+ (c x ) = f (c x ) = 9 c 5 3 x R n (x) = 9 (c x) 5 3! (x 8) On the range x [8, 8 + δ], c x may be bound by (8 + δ) and x may also be bound by (8 + δ), giving Then, when δ =. such that x [8, 8.] R n (x) = 9 (8 + δ) 5 3! R n (x) 9 (8.) 5 3! ((8 + δ) 8) = 9 (8 + δ) 5 3! (.) = 3.4 5 (δ) 6
Now, finding the error in the quadratic Taylor polynomial, f n+ (c x ) = f 3 (c x ) = R n (x) = 8 7 c 3 x 7 (c x) 8 3 (x 8) 3 On the range x [8, 8 + δ], c x may be bound by (8 + δ) and x may also be bound by (8 + δ), giving R n (x) = Then, when δ =. such that x [8, 8.] 7 (8 + δ) 8 3 ((8 + δ) 8) 3 = R n (x) = 7 (8 + δ) 8 3 (δ) 3 7 (8.) 8 3 (.) 3 =.33 7 Linear and Quadratic Taylor Polynomial Error Code for generating error plot %Code to graph the error in the linear and quadratic Taylor polynomial approximation of %(x)^(/3) %Code for finding the actual value of the function f=@(t)(t).^(/3); x=linspace(7.9,8.,); y=f(x); %Code for the linear Taylor approximation p=@(t)+(t-8)/; y=p(x); %Code for the quadratic Taylor approximation p=@(t)+(t-8)/-(t-8).^/44; y=p(x); %Calculate the error in the liner Taylor polynomial err=y-y clf semilogy(x,abs(err), r.- ); title( Taylor Polynomial Approximation Errors ) xlabel( x ) ylabel( Absolute Value of Approximation Error ) 7
hold on %Calculate the error in the quadratic Taylor polynomial err=y-y semilogy(x,abs(err), b*- ) legend( Linear Taylor Polynomial, Quadratic Taylor Polynomial ) Problem 6. Let p n (x) be the Taylor polynomial of degree n of the function f(x) = log( x). How large should one choose n for R n 4? The Taylor approximation for log( x) can be found utilizing the known Taylor approximation for x as shown below: f(x) = log( x) f (x) = = x Since the Taylor polynomial for x is well known as ( + x + x + +x 3 + + x n + xn+ x ), then the following is true, f(x) = Thus, the error term is given by t t df dx dx = t ( + x + x + x 3 + + x n )dx + t x n+ x dx and using the integral mean value theorem gives R n = c x t x n+ dx = t n+ c x n + x n+ x dx To determine how large to make n, one needs to know the interval and the target maximum error. In this problem, let R n = 4 (a)x [, ] thus, let t [, ] and since c x x let c x [, ] In creating an upper bound, bound t by and bound c x by, giving: n+ n+ R n = n + = n + 4 Then for n = 8, R n = 4 and for n = 9, R n = 8.9 5, thus a value of n = 9 is needed. (b) x [, ] thus, let t [, ] and since c x x let c x [, ] In creating an upper bound, use t = and c x =, giving Rn = ( ) n+ n + = n + 4 For this inequality to hold, a least value of n = 9998 must be chosen. Problem 7. (a) Give a Taylor approximation to f(x) about x = f(c) = x x cos(t) t dt To write the Taylor polynomial, begin with the well known Taylor polynomial for the cos(t) such that Thus, f(x) may be written as cos(t) = x! + x4 xn + + ( )n 4! (n)! + x n+ ( )n+ (n + )! cos(c) f(x) = x x [ t! + t4 tn 4! + + ( )n (n)! + ( )n+ t ] tn+ (n+)! cos(c) dt 8
= x = x = x [ x x x t! t4 tn 4! + + ( )n+ (n)! + ( )n t tn+ (n+)! cos(c)! t t(n ) + + ( )n+ + ( ) n t n 4! (n)! (n + )! cos(c)dt! t t(n ) + + ( )n+ 4! (n)! dt + x dt ( ) n t n ] (n + )! cos(c)dt In bounding the error, cos(c), so for an upper bound, assume cos(c) =, giving R n = x ( ) n t n [ ] x (n + )! dt = ( ) n x n x n = x (n + )(n + )! (n + )(n + )! The complete Taylor polynomial for f(x) may then be given by f(x) = [ x 3 4! + + ( )n+ x n (n )(n)! (b) Bound the error in the degree n approximation for x. On this boundary, one may bound x by, giving R n R n ] + ( ) n x n (n + )(n + )! (n + )(n + )! ( ) n x n (n + )(n + )! (c) Find n so as to have a Taylor approximation with an error of at most 9 on [, ] R n (n + )(n + )! 9 Thus for n = 4, R n 3. 8 and for n = 5, R n Then to satisfy the required error, one should choose n = 54 (d) Plot a graph of Cint(x) on [-,] Cint(x) x [, ] Code for Cint(x) graph %Matlab program to approximate Cint(x) x=linspace(-,,); %Create the x values to be evaluated deg=5; %Enter the degree of the Taylor approximation 9
%Calculate the coefficients for each term of the Taylor polynomial c=cint_tay(deg); %Calculate the Taylor polynomial p=polyeven(x,c,deg); plot(x,p) hold on xlabel( x ) ylabel( f(x) ) title( Cint(x) x\in [-,] ) function [ coeff ] = cint_tay( m ) %This function calculates the coefficients for the Taylor polynomial that %approximates Cint(x). coeff=ones(m,); sign=-; fact=; for i=:m sign=-sign; d=*i-; fact=fact*(*i)*(*i-); coeff(i)=sign/(d*fact); end end function [ value ] = polyeven( x,coeff,m ) %Evaluate the polynomial xsq=x.*x; value=coeff(m)*ones(size(x)); for i=m-:-: value=coeff(i)+ xsq.*value; end end