Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

it\'s a matlab question. Please show the code:) thank you Question #3-4 Marks Th

ID: 3875799 • Letter: I

Question

it's a matlab question. Please show the code:) thank you

Question #3-4 Marks The function e" can be approximated by its McLaurin series expansion as follows (note the alternating + and Alternatively, note that e-* - Thus, e-* can also be apporximated by 1 over the McLaurin series expansion of e". That is Approximate e-2 using both approaches above for n = 1, 2, 3, 4 and 5. Note, n is the degree of the polynomial not the number of terms. So here you use 2 terms, then 3 terms, ., and finally 6 terms. Compare each approximation to the true value of e20.135335 using the true relative error. What conclusions can you make about the two approaches?

Explanation / Answer

As per your requirement the below one is solution please follow it

% matlab code

actualValue = e^(-2);

x = 2;
sum = 1;
for n=1:6
sum = sum + (x)^n/factorial(n);
approxValue = 1/sum;
error = actualValue - approxValue;
fprintf("N = %d , Actual Value: %f, Approx value: %f, Relative error: %f ",n,actualValue,approxValue,error);
end

%{
output:
N = 1 , Actual Value: 0.135335, Approx value: 0.333333, Relative error: -0.197998
N = 2 , Actual Value: 0.135335, Approx value: 0.200000, Relative error: -0.064665
N = 3 , Actual Value: 0.135335, Approx value: 0.157895, Relative error: -0.022559
N = 4 , Actual Value: 0.135335, Approx value: 0.142857, Relative error: -0.007522
N = 5 , Actual Value: 0.135335, Approx value: 0.137615, Relative error: -0.002279
N = 6 , Actual Value: 0.135335, Approx value: 0.135952, Relative error: -0.000616

We can observe that the relative error decreases for higher value of N and can assume that the values will converge at some point near infinity
%}