The taylor series is a special series that approximates complicated functions as
ID: 2087998 • Letter: T
Question
The taylor series is a special series that approximates complicated functions as a polynomial. It is given by f"(a) 2 J(a) fn(a) n! where f"(a) is the i derivative of /Cxo) evaluated at a. To create the approximation, we truncate the series at some maximum term Nto give fn (a) The Taylor series is used in many scenarios, including when certain mathematical methods may not applicable (such as integration). Or for creating the finite difference approximations, as seen in the week 7 worksheet. 1) Write an algorithm for computing a taylor series to N term. 2) Write a MATLAB function that accepts three inputs (FUN, a, N), where FUN is an annonymous function, a is the point the taylor series is centered around and N is the order of the taylor series. The MATLAB function should output the Nth order Taylor series for the function about a. You are not permitted to use the taylor function in MATLAB to solve the problem. 3) Apply the function to solve the 10th order Taylor series of f(x)-e' about a-0 hint: if you choose to test your function, you can compare it to the output from wolframalpha here.Explanation / Answer
MATLAB CODE
function [ F ] = taylor2( f,a,n )
syms x
i=1;
y(i)=subs(f,x,a);
while i<=n
y(i+1)=subs(diff(f,x,i),x,a)*(x-a)^i/factorial(i);
i=i+1;
end
F=vpa(sum(y));
end
OUTPUT
>> taylor2(@(x) e^x,0,10)
ans =
0.5*x^2*log(e)^2 + 0.16666666666666666666666666666667*x^3*log(e)^3 + 0.041666666666666666666666666666667*x^4*log(e)^4 + 0.0083333333333333333333333333333333*x^5*log(e)^5 + 0.0013888888888888888888888888888889*x^6*log(e)^6 + 0.0001984126984126984126984126984127*x^7*log(e)^7 + 0.000024801587301587301587301587301587*x^8*log(e)^8 + 0.0000027557319223985890652557319223986*x^9*log(e)^9 + 0.00000027557319223985890652557319223986*x^10*log(e)^10 + x*log(e) + 1.0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.