Q4.
5
Use zero-through third order Taylor series expansions to predict f(3) for
using a base x = 1. Compute the true percent relative error Et for each approximation
Mfile Code
fprintf('f = 25*x^3 - 6*x^2 + 7*x - 88\n')
fprintf('Use zero-through third order Taylor series\n')
fprintf('expansions to predict f(3) for\n\n')
fprintf('\tf = 25*x^3 - 6*x^2 + 7*x - 88\n\n')
fprintf('using a base x = 1. Compute the true percent relative error Et for
each approximation\n\n')
fprintf('solution\n\n')
xo = 3;
true_value = 25*xo^3 - 6*xo^2 + 7*xo - 88;
x = 1;
Fd1 = 75*x^2 - 12*x + 7;
fprintf('First derivative\t: f'' = 75*x^2 - 12*x + 7,
Fd1)
Fd2 = 150*x - 12;
fprintf('Second derivative\t: f" = 150*x - 12,
Fd2)
Fd3= 150;
fprintf('Third derivative\t: f''" = 150,
Fd3)
f''(1) = %d \n',
f"(1) = %d \n',
f''"(1) = %d \n',
fprintf('For base x = 1\n')
x = 1;
T_0 = 25*x^3 - 6*x^2 + 7*x - 88;
T_1 = T_0 + (75*x^2 - 12*x + 7)*2;
T_2 = T_1 + (150*x - 12)*(2^2)/factorial(2);
T_3 = T_2 + 150*(2^3)/factorial(3);
Error_0 = (true_value - T_0)*100/true_value;
Error_1 = (true_value - T_1)*100/true_value;
Error_2 = (true_value - T_2)*100/true_value;
Error_3 = (true_value - T_3)*100/true_value;
fprintf('\tOrder\t\tExpansion and Value\t
E%%\n')
fprintf('\t0\t\t\tf(3) = %d\t\t\t\t\t\t
%0.2f%% \n',T_0, Error_0)
fprintf('\t1\t\t\tf(3) = -62 + 70(2^1) = %d\t\t
%0.2f%%
\n',T_1,Error_1)
fprintf('\t2\t\t\tf(3) = 78 + (138*(2^2))/2! =%d\t\t %0.2f%%
\n',T_2,Error_2)
fprintf('\t3\t\t\tf(3) = 354 + (150*(2^3))/3! = %d\t %0.2f%%
\n',T_3,Error_3)
Result