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

Use MATLAB fuctions to solve this The Taylor series of exp (x) can be expanded a

ID: 3797217 • Letter: U

Question

Use MATLAB fuctions to solve this

The Taylor series of exp (x) can be expanded as following e^x = Sigma^infinity_n = 1 x^n/n! = 1 + x/1! + x^2/2! + x^3/3!+... Task 1: Write a custom function to calculate exp(x) with the two input arguments are x and n (where n is the number of terms) and one output argument is the value of exp(x). Task 2: Use the function in task 1 to calculate exp(2) with 3 terms and exp(3) with 6 terms. Task 3: Calculate the error percentage between the result of exp(3) with 3 terms from task 2 and the result of exp(3) using the built-in exp() function in Matlab. If you want the error less than 0.001%, how many terms will be needed?

Explanation / Answer

Task 1 :
..................

function e = exponential(x, n)

e = 0;

for i = 0:n
e = (e + x.^i/factorial(i));
  
end

end


Task 2 (Add these below call statements in function)
........

exponential(2, 3)

exponential(3,5)


ans = 6.3333

ans = 19.412

Task 3 (Now modify the program by using below statements)
.........

l = exponential(2,3)
q = exponential(3,6)
v = exp(2)
u = exp(3)
errorPer1 = ((v - l)/100)
errorPer2 = ((u - q)/100)


l = 6.3333   
q = 19.412   
v = 7.3891   
u = 20.086   
errorPer1 = 0.010557
errorPer2 = 0.0067304

..........................................................

Now to check the error less than o.oo1% in both case
...............................................


l = exponential(2,4)
q = exponential(3,7)
v = exp(2)
u = exp(3)
errorPer1 = ((v - l)/100)
errorPer2 = ((u - q)/100)


l = 7
q = 19.846   
v = 7.3891   
u = 20.086   
errorPer1 = 0.0038906
errorPer2 = 0.0023911


...............................


l = exponential(2,5)
q = exponential(3,8)
v = exp(2)
u = exp(3)
errorPer1 = ((v - l)/100)
errorPer2 = ((u - q)/100)


l = 7.2667   
q = 20.009   
v = 7.3891   
u = 20.086   
errorPer1 = 0.0012239
errorPer2 = 7.6385e-04

.................................

l = exponential(2,6)
q = exponential(3,8)
v = exp(2)
u = exp(3)
errorPer1 = ((v - l)/100)
errorPer2 = ((u - q)/100)


l = 7.3556   
q = 20.009   
v = 7.3891   
u = 20.086   
errorPer1 = 3.3501e-04   
errorPer2 = 7.6385e-04

So , to get the error less than o.001 %, For exp(2) we need 6 terms and for exp(3) we need 8 terms.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote