% Richardson extrapolation for a forward difference.

% Approximate f'(0) = 1 for f(x) = exp(x).
h = [1; 0.5; 0.25; 0.125];

% Compute successive Richardson extrapolations.
N1 = (exp(h) - 1) ./ h;
N2 = N1(2:end) + (N1(2:end) - N1(1:end - 1));
N3 = N2(2:end) + (N2(2:end) - N2(1:end - 1)) / 3;
N4 = N3(2:end) + (N3(2:end) - N3(1:end - 1)) / 7;

fprintf('Forward difference approximations:\n')
disp(N1)
fprintf('After one extrapolation:\n')
disp(N2)
fprintf('After two extrapolations:\n')
disp(N3)
fprintf('After three extrapolations:\n')
disp(N4)
