Question
Matlab Question Only do parts c, d, and g. Parts a and b are for reference. This is a Matlab Question (Multipart-I already got someone
Matlab Question
Only do parts c, d, and g. Parts a and b are for reference.
This is a Matlab Question (Multipart-I already got someone to do a and b but they said I need to use another one of my questions to get c,d and g answered).
The Maclaurin series expansion for e^x is e^x=1 + x/1! + x^2/2! + x^3/3! +x^4/4!... and it can be expressed in summation form as e^x = x^(k-1)/((k-1)!)
The MATLAB function [exVal]=findEX(x,n) shown below can be used to calculate the value of the above series using the first n terms:
function [exVal]=findEX(x,n)
exVal=0;
for k=1:n
exVal=exVal+x.^(k-1)./factorial(k-1);
end;
a.) Using the above function approximate the value of e^(0.5), the absolute value of the true percentage relative error and the absolute value of the approximate percentage relative error for the first 5, 10, 15 and 20 terms.
b.) Modify the above function so it now calculates the absolute value of the true percentage relative error and outputs it as a second output ie. the new function should be [exVal, et] =findEX2(x,n) where et is the absolute value of the true percentage relative error. The true value of e^x can be obtained in MATLAB using exp (x)
Note: When a function has more than one output (in this case findEX2() has two outputs - exVal, et), then you need to call/execute the function with all the outputs in the command window. E.g. if you want to get exVAL and et for x=0.1 and n=3, you should call/execute the function as:
>>[exVal, et] = findEX2 (0.1,3)
It would be inadvisable to call/execute as >>findEX2 (0.1,3) because then, MATLAB will just show you the first output (and second and subsequent outputs will be lost)
c.) Using the function findEX2, check the absolute value of the true percentage relative error found in (a) for 5, 10, 15, and 20 terms.
d.) Modify the above function so that it now calculates the absolute value of the approximate percentage relative error and outputs it as a third output i.e. the new function should be [exVal, et, ea] =findEX3 (x,n) where ea is the absolute value of the approximate percentage relative error. Keep in mind note from (b)
g.) Using the function findEX3, check the absolute value of the approximate percentage relative error found in (a) for 5, 10, 15, and 20 terms.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started