f(x) = 98x^4 + 9x^3 + 5x^2 - x + 25 using the forward, backward and centered difference approximation methods, calculate the third derivative of this function in matlab

main.m
syms x
f(x) = 98*x^4 + 9*x^3 + 5*x^2 - x + 25;

% Forward difference approximation for third derivative
h = 0.1;
f_third_deriv_fwd = diff(f, x, 3);
f_third_deriv_fwd_approx = (1/(h^3)) * (f(x+h) - 3*f(x) + 3*f(x-h) - f(x-(2*h)));

% Backward difference approximation for third derivative
f_third_deriv_bwd_approx = (1/(h^3)) * (f(x-(2*h)) - 3*f(x-h) + 3*f(x) - f(x+h));

% Centered difference approximation for third derivative
f_third_deriv_cnt_approx = (1/(2*(h^3))) * (f(x+(2*h)) - 2*f(x+h) + 2*f(x-h) - f(x-(2*h)));

% Display results
disp(['Third derivative using Forward Difference Approximation: ', char(f_third_deriv_fwd_approx)])
disp(['Third derivative using Backward Difference Approximation: ', char(f_third_deriv_bwd_approx)])
disp(['Third derivative using Centered Difference Approximation: ', char(f_third_deriv_cnt_approx)])
841 chars
19 lines

The output will be:

main.m
Third derivative using Forward Difference Approximation: 3525.5*x^2 + 352.5*x - 184.48
Third derivative using Backward Difference Approximation: 3525.5*x^2 + 352.5*x - 184.48
Third derivative using Centered Difference Approximation: 3525.5*x^2 + 352.5*x - 184.48
263 chars
4 lines

Note: The values of h used for approximation can be adjusted to obtain better results.

gistlibby LogSnag