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.
Show older comments
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))/h
Error_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
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!