Question
THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...
THE CODE NEEDS TO BE ON MATLAB
Answers
error=1; %starting value for error
maclaurin_value=0; % starting value for value calculated from maclaurin series
n=0; %starting power
x=2; %power to which e has to be raised to
i=0; %iteration number
while error > 0.01
i=i+1; %increment iteration number
maclaurin_value=maclaurin_value+ (x^n)/factorial(n); %calculate approximation
error=abs(exp(2)-maclaurin_value); %calculate error
fprintf("iter = %d",i);
fprintf(", approx = %f",maclaurin_value);
fprintf(", error = %f \n",error);
n=n+1; %increment exponent to get the next term in the maclaurin series
end
fprintf("exact value = %f",exp(2));
Output of this script
2. The second question refers to a program which is not included in the question. Please include the program which is (according to the question) available on the previous page.