Question: I have created a Matlab function that approximates e^x using the infinite series and truncating it to n terms I specifically need to modify this
I have created a Matlab function that approximates e^x using the infinite series
and truncating it to n terms
I specifically need to modify this code so for n = 10, the relative error between the approximation and actual value is
Here is the code:
function [err] = approx(n,x)
if(x
s = x * (-1);
else
s = x;
end
t = zeros(1, n+1);
for ii = 0:n
t(ii + 1) = (s.^ii)/factorial(ii);
end
tSum = sum(t);
if(x
finalSum = 1/tSum;
else
finalSum = tSum;
end
err = abs(exp(x) - finalSum)/finalSum
end
lim nex ito
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
