f = x^3+2x^2-x+3;%actual derivative of function
fprime = 3x^2+4x-1; %step size:
h=0.1; %forward difference
dfdx_forward = f(1+h)-f(1)/h Error_forward = fprime(1)-dfdx_forward %error
%backward difference
dfdx_backward = (f(1)-f(1-h))/hError_backward = fprime(1)-dfdx_backward %error %central difference
dfdx_central = (f(1+h)-f(1-h))/(2*h)Error_central = fprime(1)-dfdx_central %error
MATLAB: Error: File: Untitled11.m Line: 1 Column: 10 Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
numerical methods
Best Answer