function bpath2 ( )

%*****************************************************************************80
%
%% bpath2() performs a vectorized 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:
%
%    27 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, 'bpath2():\n' );
  fprintf ( 1, '  Brownian path simulation\n' );

% rng ( 'shuffle' );

  T = 1.0; 
  N = 500; 
  dt = T / N;
%
%  dW contains the increments.
%
  dw = sqrt ( dt ) * randn ( 1, N );
%
%  W(I) contains the cumulative sum of the increments 1 through I.
%
  w0 = 0.0;
  w = cumsum ( dw );
%
%  Plot t versus W(t).
%
  clf ( );
  hold ( 'on' );
  plot ( [0:dt:T], [w0,w], 'LineWidth', 3, 'Color', 'b' );
  plot ( [0, T], [0.0, 0.0], 'LineWidth', 2, 'Color', 'k' );
  grid ( 'on' );
  title ( 'Brownian path realization computed by BPATH2' );
  xlabel ( 't', 'FontSize', 16 );
  ylabel ( 'W(t)', 'FontSize', 16, 'Rotation', 0 );
  hold ( 'off' );

  filename = 'bpath2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as %s\n', filename );

  return
end
