I want write a script in MATLAB that computes the quotient of the derivative (f(x+h)-f(x))/h for the function x^2 at x=2 and h starting at 1 and decreasing by a factor of 10, and the book said that the effect of the rounding error becomes apparent when h gets to small (less than 10^-12).
Then I wrote the following code:
for i=0:-2:-16
h=10^i;
((2+h)^2-(2)^2)./h
end
Then my question is, How can I improve my code? because It gives me indeed an error saying that the last approximation to the derivative is zero.
Thanks a lot in advance :)