function u = forward2 ( e, r, sigma, t1, nx, nt, l )

%*****************************************************************************80
%
%% forward2() uses the forward difference method to value a European call option.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    28 March 2005
%
%  Author:
%
%    Original MATLAB version by Desmond Higham.
%    Modifications by John Burkardt.
%
%  Reference:
%
%    Desmond Higham,
%    Black-Scholes for Scientific Computing Students,
%    Computing in Science and Engineering,
%    November/December 2004, Volume 6, Number 6, pages 72-79.
%
%  Input:
%
%    real E, the exercise price.
%
%    real R, the interest rate.
%
%    real SIGMA, the volatility of the asset.
%
%    real T1, the expiry date.
%
%    integer NX, the number of "space" steps used to divide the 
%    interval [0,L].
%
%    integer NT, the number of time steps.
%
%    real L, the maximum value of S to consider.
%
%  Output:
%
%    real U(NX-1,NT+1), the value of the European call option.
%
  k = t1 / nt;
  h = l / nx;

  a(1:nx-1,1:nx-1) = 0.0;
  for i = 1 : nx - 1
    a(i,i) = ( 1.0 - r * k );
  end
  a
  for i = 1 : nx - 1
    a(i,i) = a(i,i) - k * ( sigma * i )^2;
  end
  a

  for i = 1 : nx - 2
    a(i,i+1) = 0.5 * k * ( sigma * i )^2 + 0.5 * k * r * i;
  end

  for i = 2 : nx - 1
    a(i,i-1) = 0.5 * k * ( sigma * i )^2 - 0.5 * k * r * i;
  end

  a

  u = zeros ( nx - 1, nt + 1 );

  u0 = 0.0;
  for i = 1 : nx - 1
    u0 = u0 + h;
    u(i,1) = max ( u0 - e, 0.0 );
  end
 
  for j = 1 : nt

    tau = ( j - 1 ) * t1 / nt;

    p = 0.5 * k * ( nx - 1 ) * ( sigma * sigma * ( nx - 1 ) + r ) ...
      * ( l - e * exp ( - r * tau ) );

    u(:,j+1) = a * u(:,j);

    u(nx-1,j+1) = u(nx-1,j+1) + p;

  end

  return
end
