function y = reaction_twoway_exact ( t )

%*****************************************************************************80
%
%% reaction_twoway_exact returns the exact solution of the twoway reaction ODE.
%
%  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
%
%  Input:
%
%    real T: the current time.
%
%  Output:
%
%    real Y(2): the exact solution.
%
  [ k1, k2, t0, y0 ] = reaction_twoway_parameters ( );

  w10 = y0(1);
  w20 = y0(2);

  w1 = ( k2 * ( w10 + w20 ) ...
     + exp ( - ( k1 + k2 ) * t ) * ( k1 * w10 - k2 * w20 ) ) / ( k1 + k2 );
  w2 = ( k1 * ( w10 + w20 ) ...
     - exp ( - ( k1 + k2 ) * t ) * ( k1 * w10 - k2 * w20 ) ) / ( k1 + k2 );

  y = [ w1, w2 ];

  return
end
