Consider the function f(x) = e
x where e = 2.718 . . . is the base of the natural logarithm
(ln = loge
), sometimes known as Napier’s constant. For x close to 0, e
x
can be approximated by a
finite Taylor series:
e
x ≈ s = 1 + x +
x
2
2! +
x
3
3! +
x
4
4! + · · · +
x
p
p!
where p is a positive integer.
(a) Write a MATLAB program with a for loop to compute (and display) the approximation s of
e
x and the difference d = s − e
x
for p = 1, 2, . . . , num where x and num are entered by the user.
Your program should use format long e and display the values s and d in two columns
with appropriate headings. (Recall that e
x
can be computed in MATLAB using exp(x).)
(b) Run your program with x = 0.5 and num = 10.
(c) Use your program to find the smallest value of p for which the difference s − e
0.5 is less than
10−14 in absolute value.