By using MATLAB codes answer the following questions ( need to show commands win
ID: 3111740 • Letter: B
Question
By using MATLAB codes answer the following questions ( need to show commands window) Format long e . . .estimate e? Relativerror? Actual value for e? Absoluterror ? Number of termas ?By using MATLAB answer the following questions Format long e Estimate e: Actual value for e: Abserr estimate-actual Relative error estimate-actual/1 actual : The number of terms: 3) One method by which we can approximate the constant e is with a series a) Write a MATLAB script m-file that uses the Maclaurin series, to compute an approximation for e. Let your program add terms until the running sum no longer changes. (You may need to keep track of both a current and a previous running sum) Display the approximation, the absolute error, the relative error, and the number of terms needed in the series for this approximation. Use MATLAB's built-in function exp for the "exact" value of e in your error calculations b) Why does the running sum eventually stop changing? What phenomenon is occurring here that we discussed in class?
Explanation / Answer
clc;
clear all;
s=0;
n=20;
x=1;
for i=1:n
s=s+x/factorial(i);
y(i)=1+s;
end
y(end) % aproximate value
yex=exp(1) % actula value
erorr=abs(y-yex); % abs erorr
rel_err=abs(erorr/yex); % relative erorr
erorr'
rel_err'
ans =
2.718281828459046
yex =
2.718281828459046
ans =
0.718281828459046
0.218281828459046
0.051615161792379
0.009948495125712
0.001615161792379
0.000226272903490
0.000027860205077
0.000003058617775
0.000000302885853
0.000000027312661
0.000000002260553
0.000000000172877
0.000000000012286
0.000000000000815
0.000000000000051
0.000000000000003
0
0
0
0
ans =
0.264241117657115
0.080301397071394
0.018988156876154
0.003659846827344
0.000594184817582
0.000083241149288
0.000010249196675
0.000001125202598
0.000000111425478
0.000000010047766
0.000000000831611
0.000000000063598
0.000000000004520
0.000000000000300
0.000000000000019
0.000000000000001
0
0
0
0
n=20
clc;
clear all;
format long
s=0;
n=7
x=1;
for i=1:n
s=s+x/factorial(i);
y(i)=1+s;
end
y(end) % aproximate value
yex=exp(1) % actula value
erorr=abs(y(end)-yex); % abs erorr
rel_err=abs(erorr/yex); % relative erorr
erorr'
rel_err'
n =
7
ans =
2.718253968253968
yex =
2.718281828459046
erorr =
2.786020507716813e-005
rel_err =
1.024919667471039e-005
clc;
clear all;
format long
s=0;
n=20;
x=1;
n=0;
erorr=0.1;
tol=1e-10;
while (erorr>tol)
s=s+x/factorial(n);
y=s
n=n+1
yex=exp(1); % actula value
erorr=abs(y-yex); % abs erorr
rel_err=abs(erorr/yex); % relative erorr
end
y
yex=exp(1) % actula value
erorr'
rel_err'
n =
14
y =
2.718281828446759
yex =
2.718281828459046
erorr =
1.228617207971183e-011
rel_err =
4.519830118820566e-012
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.