Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 itoStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started