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

Matlab Homework Maclauren Series - Need Help Evaluate e^- using following approa

ID: 3782758 • Letter: M

Question

Matlab Homework Maclauren Series - Need Help

Evaluate e^- using following approaches e^-x = 1 - x + x^2/2 - x^3/31 + ..., and e^-x = 1/(e^x) = 1/(1 + x + x^2/2+ x^3/3!+....), and compare with the true value of 6.737947 times 10^-3. Use 20 terms to evaluate each series and compute the error as terms are added. The error can be computed as follows e=100*[true value - series value]/true value. Your function should call other functions with the headings below. function [SeriesValuel,TrueValuel, errorl] = MaclaurinExpXTerml (number, order); %input: x is a real number, n is a positive integer %output: The numerical value and error for the nth term of the Maclauren series for exp(x). function [SeriesValue2,TrueValue2, error2] = MaclaurinExpXTerm2 (number, order); %input: x is a real number, n is a positive integer %output: The numerical value and error for the nth term of the Maclauren series for exp(x).

Explanation / Answer

Matlab code:

1) Create file driver.m and paste below code in it.

[SeriesValue_1,TrueValue_1,error_1] = MaclaurinExpXTerm1(20,5)
[SeriesValue_2,TrueValue_2,error_2] = MaclaurinExpXTerm2(20,5)

2) Create file MaclaurinExpXTerm1.m and paste below code in it.

function[SeriesValue_1,TrueValue_1,error_1] = MaclaurinExpXTerm1(number,order)
x = order;
format long
series_value = 1.0;
for i = 1:number
series_value = series_value + (((-1)^(i))*(x)^i)/factorial(i);
end
SeriesValue_1 = series_value;
TrueValue_1 = exp(-order);
error_1 = 100*(abs(TrueValue_1 - SeriesValue_1)/TrueValue_1);
end

3) Create file MaclaurinExpXTerm2.m and paste below code in it.

function[SeriesValue_2,TrueValue_2,error_2] = MaclaurinExpXTerm2(number,order)
x = order;
format long
denominator = 1.0;
for i = 1:number
denominator = denominator + ((x)^i)/factorial(i);
end
SeriesValue_2 = 1/denominator;
TrueValue_2 = exp(-order);
error_2 = 100*(abs(TrueValue_2 - SeriesValue_2)/TrueValue_2);
end

You need to run driver.m file only, this files calls the functions defined in other two files.

Sample Output:

SeriesValue_1 =

0.006745540097712


TrueValue_1 =

0.006737946999085


error_1 =

0.112691575451409


SeriesValue_2 =

0.006737947545483


TrueValue_2 =

0.006737946999085


error_2 =

8.109251128516721e-06