% Find the best step size for central differences.

% Approximate f'(0) = 1 for f(x) = exp(x).
h = 10.^(-15:0.1:0);
df = (exp(h) - exp(-h)) ./ (2 * h);
err = abs(df - 1);

loglog(h, err)
xlabel('h')
ylabel('Error')
grid on

% Print the predicted best step size.
hbest = (3e-16)^(1 / 3);
fprintf('Predicted best step size: h = %.3e\n', hbest)
