In: Advanced Math
Use matlab to plot Taylor approximation for f(x) for x near 0 Given f(x) = exp(x)
Use subpots to plot and its absolute and realative erros for N= 1,2,3
PLease give matlab code for Taylor and explain in detail, Thank you
syms x
f = exp(x);
T1 = taylor(f, x,'Order',1)
T2 = taylor(f, x, 'Order', 2)
T3 = taylor(f, x, 'Order', 3)
fplot([T1 T2 T3 f])
xlim([-4 4])
grid on
legend('approximation of exp(x) up to O(x)',...
'approximation of exp(x) up to
O(x^2)',...
'approximation of exp(x) up to
O(x^{3})',...
'exp(x)','Location','Best')
title('Taylor Series Expansion')
or one can paste the code given below
syms x
f = exp(x);
T1 = taylor(f, x,'Order',1)
T2 = taylor(f, x, 'Order', 2)
T3 = taylor(f, x, 'Order', 3)
subplot(4,1,1);
x = linspace(0,10);
y1 = exp(x);
fplot([T1 f])
xlim([-4 4])
grid on
legend('approximation of exp(x) up to O(x)')
title('Taylor Series Expansion')
subplot(4,1,2);
x = linspace(0,10);
f = exp(x);
fplot([T2 f])
xlim([-4 4])
grid on
legend('approximation of exp(x) up to O(x^2)')
title('Taylor Series Expansion')
subplot(4,1,3);
x= linspace(0,10);
f= exp(x);
fplot([T3 f])
xlim([-4 4])
grid on
legend('approximation of exp(x) up to O(x^3)')
title('Taylor Series Expansion')
subplot(4,1,4);
x = linspace(0,10);
f = exp(x);
fplot([T4 f])
xlim([-4 4])
grid on
legend('approximation of exp(x) ')
title('Taylor Series Expansion')