Create MATLAB that calculates e^x using the following formula, and measure the a
ID: 1716140 • Letter: C
Question
Create MATLAB that calculates e^x using the following formula, and measure the absolute error from the MATLAB provided function.
ELEN 3381 Assignment #4 Due date : Shown on the Blackboard. Please submit: 1. Your MATLAB / Scilab code. 2. Copy of a screenshot after your program is executed. Create MATLAB code that calculates ex using the following formula, and measure the absolute error from the MATLAB provided function. The Taylor series for the exponential functioned 1+ 1! 2!! 45 .. 3 1+ T + - 2 - - - - - THE 6 '24'120 n=0 Plot both (1) the approximated value, and (2) absolute error The following example uses x = -10, and n = 50. Choose your own x, and in values. Approximation: Green with circle, Error: Blue. (Explanation / Answer
MATLAB code for Taylor series is,
clear all
close all
clc
n=input('Enter n value : ');
syms x
e_x=0;
for i=1:n
y=power(x,i)/factorial(i);
e_x=e_x+y;
end
op=1+e_x;
disp(op)
result is:
Enter n value : 5
x^5/120 + x^4/24 + x^3/6 + x^2/2 + x + 1
>>
now place x=-10 and n=50, the code is
clear all
close all
clc
n=input('Enter n value : ');
x=input('Enter x value : ');
e_x=0;
for i=1:n
y=power(x,i)/factorial(i);
e_x=e_x+y;
end
actual_value=exp(x)
approximated_value=1+e_x
absolute_error=100*(actual_value-approximated_value)/(approximated_value)
results are:
Enter n value : 50
Enter x value : -10
actual_value =
4.5400e-005
approximated_value =
4.5400e-005
absolute_error =
7.2212e-007
>>