An approximation S to e^x can be computed by using the Taylor series for the exp
ID: 2085636 • Letter: A
Question
An approximation S to e^x can be computed by using the Taylor series for the exponential function: S: = 1 P: = 1 for k = 1, 2, ... begin P: = xP/k S: = S + P end k. The loop can be stopped when S = S + P to machine precision. (a) Try this algorithm with x = -10 using single precision arithmetic. What was k when you stopped? What is the relative error in the resulting approximation? Does this appear to be a good way to compute e^-10 to full machine precision? (b) Repeat (a) with x = + 10. (c) Why are the results so much more reasonable for (b)? (d) What would be a computationally safe way to compute e^-10?Explanation / Answer
The Matlab code for the algorithm is as shown below :
------------------------------------------------------------------------------------
%% Algorithm for e^x approximation.
%% Initialization
S = 1;
P = 1;
iteration_error = 1;
k = 1;
x = -10;
while (iteration_error ~= 0)
P = single(x*P/k);
S = single(S + P);
iteration_error = P;
k = k+1;
end
------------------------------------------------------------------------------------
(a). The iteration stopped at k = 88 for x = -10. The relative error from the resulting approximation is 1.0796e-004. But, the value through the algorithm is negative while e^-10 is possitive. So, this is not a good way to approximate exponents.
(b). The iteration stopped at k = 88 for x = 10. The relative error from the resulting approximation is 0.003. This seems to be a good way to approximate positive exponents.
(c). The results are reasonable for (b) because the algorithm does not factor in the fact that exponents are always positive irrespective of the values of x properly. So, for positive x, the algorithm seems to be working correctly.
(d). A computationally sound way to compute e^-10 through this algorithm can be to find e^10 first and then divide the obtained value by 1. This would ensure a correct value of e^-10.
Let me know your feedback on the same.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.