function reaction_ode_test ( )

%*****************************************************************************80
%
%% reaction_ode_test tests reaction_ode().
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    22 January 2021
%
%  Author:
%
%    John Burkardt
%
  timestamp ( );
  fprintf ( 1, '\n' );
  fprintf ( 1, 'reaction_ode_test:\n' );
  fprintf ( 1, '  MATLAB/Octave version %s\n', version ( ) );
  fprintf ( 1, '  Test reaction_ode().\n' );
%
%  Get parameter values.
%
  [ k, t0, y0 ] = reaction_parameters ( );
%
%  Report parameter values.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Reaction differential equation:\n' );
  fprintf ( 1, '    da/dt = - k a b\n' );
  fprintf ( 1, '    db/dt = - k a b\n' );
  fprintf ( 1, '    dc/dt = + k a b\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Parameter values:\n' );
  fprintf ( 1, '    k  = %g, (reaction rate)\n', k);
  fprintf ( 1, '    t0 = %g, (initial time, in seconds s)\n', t0 );
  fprintf ( 1, '    a0 = %g, (initial amount of species a in Mol/L)\n', y0(1) );
  fprintf ( 1, '    b0 = %g, (initial amount of species b in Mol/L)\n', y0(2) );
  fprintf ( 1, '    c0 = %g, (initial amount of species c in Mol/L)\n', y0(3) );
%
%  Solve the equation.
%
  f = @ reaction_deriv;
  tmax = 20.0;
  tspan = [ t0, tmax ];

  [ t, y ] = ode45 ( f, tspan, y0 );
%
%  Evaluate exact solution.
%
  ye = reaction_exact ( t );
%
%  Plot.
%
  figure ( 1 );
  clf ( );
  plot ( t, y(:,1), 'ro', t, y(:,2), 'go', t, y(:,3), 'bo', ...
         t, ye(:,1), 'c-', t, ye(:,2), 'm-', t, ye(:,3), 'y-', ...
         tspan, [0.0,0.0], 'k-', ...
         'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<---  t  --->' );
  ylabel ( '<---  Concentrations  --->' );
  title ( 'A+B --k--> C reaction' );
  legend ( 'A', 'B', 'C', 'Aexact', 'Bexact', 'Cexact', 'x axis', 'Location', 'North' );
  filename = 'reaction_solution.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  h = reaction_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: reaction' );
  legend ( 'h', 'h initial', 'x axis' );
  filename = 'reaction_conserved.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'reaction_ode_test:\n' );
  fprintf ( 1, '  Normal end of execution.\n' );
  fprintf ( 1, '\n' );
  timestamp ( );

  return
end
