TaylorExample - Taylor0 = fxi0*ones(npts,1) Taylor1 =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 function TaylorExample % Example program to show how a Taylor series approximates % a function at other values of the independent variable as % as more and more derivatives are added to the series at % the current value of the independent variable % Plot true function for 0 <= x <= 1 x = [0:0.05:1]' npts = length(x) fxtrue = -0.1*x.^4-0.15*x.^3-0.5*x.^2-0.25*x+1.2 plot(x,fxtrue,'k-') xlabel('x') ylabel('f(x)') legend('true') pause % Calculate f(x) and its first five derivatives at x = 0 xi = 0 fxi0 = -0.1*xi.^4-0.15*xi.^3-0.5*xi.^2-0.25*xi+1.2 f1xi0 = -4*0.1*xi.^3-3*0.15*xi.^2-2*0.5*xi-0.25 f2xi0 = -3*4*0.1*xi.^2-2*3*0.15*xi-2*0.5 f3xi0 = -2*3*4*0.1*xi-2*3*0.15 f4xi0 = -2*3*4*0.1 f5xi0 = 0 % Form Taylor series approximations to f(x) at x = 1 xiplus1 = x dx = (xiplus1-xi)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Taylor0 = fxi0*ones(npts,1) Taylor1 = Taylor0+f1xi0*dx Taylor2 = Taylor1+(f2xi0/factorial(2))*dx.^2 Taylor3 = Taylor2+(f3xi0/factorial(3))*dx.^3 Taylor4 = Taylor3+(f4xi0/factorial(4))*dx.^4 Taylor5 = Taylor4+(f5xi0/factorial(5))*dx.^5 % Note that these Taylor series are basically polynomial approximations % to the original function. % Question: The original function went up to x^4. Theoretically, what is % the highest derivative that we need in the Taylor series to match the % original function EXACTLY at any new point x(i+1)? hold on plot(x,Taylor0,'ro-') pause plot(x,Taylor1,'gro-') pause plot(x,Taylor2,'bo-') pause plot(x,Taylor3,'co-') pause plot(x,Taylor4,'mo-') Sheet1 Page 2 pause plot(x,Taylor5,'yo-')...
View Full Document

This note was uploaded on 09/05/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Page1 / 2

TaylorExample - Taylor0 = fxi0*ones(npts,1) Taylor1 =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online