function reaction_twoway_ode_test ( )

%*****************************************************************************80
%
%% reaction_twoway_ode_test tests reaction_twoway_ode().
%
%  Discussion:
%
%    The reference suggests an experiment in which the Forward Euler method
%    is used, with a timestep of 1/50.  The problem is to be solved three
%    times, with the second reaction coefficient, k2, set to 10 (the default), 
%    100, and 1000.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    31 January 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Willem Hundsdorfer, Jan Verwer,
%    Numerical solution of time-dependent advection-diffusion-reaction equations,
%    Springer, 2003
%    ISBN: 978-3-662-09017-6
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'reaction_twoway_ode_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test reaction_twoway_ode().\n' );
%
%  Get parameter values.
%
  [ k1, k2, t0, y0 ] = reaction_twoway_parameters ( );
%
%  Report parameter values.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Reaction differential equation:\n' );
  fprintf ( 1, '    dW1/dt = - k1 W1 + k2 W2\n' );
  fprintf ( 1, '    dW2/dt = + k1 W1 - k2 W2\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameter values:\n' );
  fprintf ( 1, '    k1 =  %g, (reaction rate)\n', k1 );
  fprintf ( 1, '    k2 =  %g, (reaction rate)\n', k2 );
  fprintf ( 1, '    t0 =  %g, (initial time, in seconds s)\n', t0 );
  fprintf ( 1, '    W10 = %g, (initial amount of species W1)\n', y0(1) );
  fprintf ( 1, '    W20 = %g, (initial amount of species W2)\n', y0(2) );
%
%  Solve the equation.
%
  f = @ reaction_twoway_deriv;
  tmax = 1.0;
  tspan = [ t0, tmax ];

  [ t, y ] = ode45 ( f, tspan, y0 );
%
%  Evaluate exact solution.
%
  ye = reaction_twoway_exact ( t );
%
%  Plot.
%
  figure ( 1 );
  clf ( );
  plot ( t, y(:,1), 'ro', t, y(:,2), 'go', ...
         t, ye(:,1), 'c-', t, ye(:,2), 'm-', ...
         tspan, [0.0,0.0], 'k-', ...
         'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<---  t  --->' );
  ylabel ( '<---  Concentrations  --->' );
  title ( 'Two-way reaction' );
  legend ( 'W1', 'W2', 'W1exact', 'W2exact', 'x axis', 'Location', 'North' );
  filename = 'reaction_twoway_solution.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = reaction_twoway_conserved ( y );

  figure ( 2 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'r-', ...
           tspan, [h(1),h(1)], 'b--', ...
           tspan, [0.0,0.0], 'k-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<---  t  --->' );
  ylabel ( '<---  conserved quantity  --->' );
  title ( 'conserved: two-way reaction' );
  legend ( 'h', 'h initial', 'x axis' );
  filename = 'reaction_twoway_conserved.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'reaction_twoway_ode_test:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end
