Question: MATLAB - In class, we wrote the code for successive Taylor approximations of e x . Now we want to do error analysis. I have

MATLAB - In class, we wrote the code for successive Taylor approximations of e x . Now we want to do error analysis. I have given you that code and an additional code for this problem. In one figure, plot the actual error and also plot the max error bound the remainder term in the Taylor series provides. In a second figure, plot the difference between these two. Briefly explain why there is a difference.

Taylor Series

x = -4:.01:4; y = exp(x);

figure hold on grid on

plot(x,y)

x0 = 1; T1 = exp(x0)+exp(x0)*(x-x0);

T2 = T1 + (exp(x0)/factorial(2))*(x-x0).^2;

plot(x, T1) plot(x, T2)

figure hold on

plot(x, abs(T1 - y)) plot(x, abs(T2 - y))

Other Code

actual_errors = zeros(1,20); %this makes a 20 entry array to put your answers in error_term = zeros(1,20); x = [-4:.01:4]; x0 = 1; func = exp(x); T0 = exp(x0); T_approx = T0; for i = 1:20 T_i = exp(x0).*((x-x0).^i)/factorial(i); T_approx = T_approx + T_i; actual_errors(i) = max(abs(T_approx-func)); % for below, consider tthe above as being in the form coefficient.*((x-x0).^i)/factorial(i) % The Taylor error term is given by maximizing the % coefficient for the (i+1) term %T_coefficient = max(abs(___your term here____)); %put in the term for %the (i+1)th %coefficient %T_iplus = T_coefficient.*(____put the rest here___); %fill in the rest %of the (i+1)th term %T_iplus is the Taylor error Term. error_term(i) = max(abs(T_iplus)); end

figure hold on plot(1:20, actual_errors, '*') % the asterisk makes it print a larger %* to make point plots more visible plot(1:20, error_term, '*')

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!