function dydt = reaction_twoway_deriv ( t, y )

%*****************************************************************************80
%
%% reaction_twoway_deriv: right hand side of the twoway reaction ODE.
%
%  Discussion:
%
%    The reactions involve chemicals W1 and W2, and have the form
%
%    dW1dt = - k1 W1(t) + k2 W2(t)
%    dW2dt = + k1 W1(t) - k2 W2(t)
%
%  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, Y(2): the time and variable values.
%
%  Output:
%
%    real DYDT(2): the right hand sides of the ODE.
%
  [ k1, k2, t0, y0 ] = reaction_twoway_parameters ( );

  w1 = y(1);
  w2 = y(2);

  dw1dt = - k1 * w1 + k2 * w2;
  dw2dt = + k1 * w1 - k2 * w2;
 
  dydt = [ dw1dt; dw2dt ];

  return
end
