Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

*MATLAB code* Only have access to Matlab to check work. Please show where scipt

ID: 3733903 • Letter: #

Question

*MATLAB code* Only have access to Matlab to check work. Please show where scipt file ends. I DO give thumbs up for correct work. Thank you!

--> Problem:

Using while loop write down a general matlab code to calculate e summation from the Taylor Series 4 xn n! Let the summation of Taylor Series to be a. Also let the exponential value using matlab function EXP(x) to be b. b exp (x) Then we define the error as: -a er Your code shall find the exponential using Taylor Series with an error er s 0.01. In other words the condition to terminate the while loop is not n iterations as we did in the class work but it is the error value to be less than 0.01. The output of the code will be a as well as n. Save your code as a script file named HW35

Explanation / Answer

prompt = 'Enter x : ';

% get user input

x = input(prompt);

% store the value of e^x

a = 0;

% get the value form predefined function

b = exp(x);

i = 0;

% calculate error

er = abs( ( b - a ) / b );

while er > 0.01

  

   a = a + ( ( x ^ i ) / factorial(i) );

   % calculate error

   er = abs( ( b - a ) / b );

  

   i = i + 1;

   

end

fprintf(' Calculated e^%f : %f', x, a);

fprintf(' Standard e^%f : %f', x, b);

Sample Output

Enter x : 2.36

Calculated e^2.360000 : 10.558958
Standard e^2.360000 : 10.590951