function bpath1 ( )

%*****************************************************************************80
%
%% bpath1() performs a Brownian path simulation.
%
%  Discussion:
%
%    This routine computes one simulation of discretized Brownian 
%    motion over the time interval [0,1] using 500 time steps.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    26 September 2006
%
%  Author:
%
%    Desmond Higham
%
%  Reference:
%
%    Desmond Higham,
%    An Algorithmic Introduction to Numerical Simulation of
%    Stochastic Differential Equations,
%    SIAM Review,
%    Volume 43, Number 3, September 2001, pages 525-546.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'bpath1()\n' );
  fprintf ( 1, '  Brownian path simulation\n' );

% rng ( 'shuffle' );

  t = 1.0; 
  n = 500; 
  dt = t / n;
%
%  Define the increments dW.
%
  dw = sqrt ( dt ) * randn ( 1, n );
%
%  W is the sum of the previous increments.
%
%  MATLAB does not allow zero-based indexing.
%  Otherwise, we would set W(0) = 0.  We
%  can fake it with a variable called W0, however!
%
  w = zeros(1,n);

  w0 = 0.0;
  
  for j = 1 : n

    if ( j == 1 )
      w(j) = w0 + dw(j);
    else
      w(j) = w(j-1) + dw(j); 
    end

  end
%
%  Plot W(t) against t.
%  We can include time 0 and value W0 in the plot.
%
  clf ( );
  hold ( 'on' );
  plot ( [0:dt:t], [w0,w], 'LineWidth', 3, 'Color', 'b' );
  plot ( [0, t], [0.0, 0.0], 'LineWidth', 2, 'Color', 'k' );
  title ( 'Brownian motion realization by BPATH1' );
  xlabel ( 't', 'FontSize', 16 ) ;
  ylabel ( 'W_t', 'FontSize', 16, 'Rotation', 0 );
  grid ( 'on' );
  hold ( 'off' );
  filename = 'bpath1.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as %s\n', filename );

  return
end
