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

I have created a Matlab function that approximates e^x using the infinite 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

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!