Matlab code:
a = 0.2;
x = -5: .01 : 5;
f =@(a) exp(-a);
f_1 =@(a) -exp(-a);
f_2 =@(a) exp(-a);
f_3 =@(a) -exp(-a);
T_0 = f(a) * x.^0;
T_1 = T_0 + f_1(a) * (x - a);
T_2 = T_1 + ((f_2(a))/factorial(2)) *(x - a) .^2;
T_3 = T_2 + ((f_3(a))/factorial(3)) *(x - a) .^3;
hold on
plot(x,exp(-x))
plot(x,T_0, 'r')
plot(x,T_1,'g')
plot(x,T_2, 'k')
plot(x,T_3, 'm')
hold off
This plots the expansions out to the third order as requested by the problem and produces the graph:
As you can see, the zeroth order taylor in red is the farthest from approximating the actual equation in blue, the first order in green is closer, the second in black even closer, and the third in magenta is closest. They all converge at .2, the x we were solving for.
No comments:
Post a Comment