%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Taylor approximation: e^x % f(x) = e^x = pn(x) + Rn(x) % Figure1.1 on textbook page 5 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% close all clc clear set(0,'DefaultFigureWindowStyle','docked') x = -1.5:0.01:1.5; % x fx = exp(x); % original exp() from matlab p2 = myexp(x,2); % my version of exp() with n = 3 p9 = myexp(x,9); % my version of exp() with n = 5 figure plot(x,fx); % plot fx hold on % keep the first plot on plot(x,p2,':'); % plot y1 in red plot(x,p9,'--r'); % plot y2 in green hold off title('exp(t) and its taylor series approximation') % title of the plot xlabel('x') % lable of x axis ylabel('magnitude') % lable of y axis legend('exp(x)','P_2(x)','P_9') grid on