writing a matlab script to approximate exp(x) at exp(.05) using ""Taylor series"" ""and"" a ""while loop"".
a=.05 is very close to a convenient x value. The allowable error (error = |guess-true|) is to be less than or equal to 10^-9.
I also need to figure out how many terms in the Taylor series were required to achieve convergence. Plot the n=1, n=2, n=3 approximations to e^x for x=0:0.05:1, and plot the built-in exp(x) function on this same interval. Ensure that each line has a unique LineSpec format (ie- line style, tickmark, color), and provide a legend identifying your four curves. Label x and y axes as "Domain" and "Range".
This is what I have so far. How do I add the 3 n values. I JUST NEED TO ADD THE N-1, N-2, N-3 But I don't know how.
clear, clc
err = 1;
order = 1;
while err > 0.000000001
syms x;
approx = taylor(exp(x),x,'Order',order);
x = 0.05;
approx = eval(approx);
err = abs(exp(0.05) - approx);
order = order + 1
end