function dydt = doughnut_deriv ( t, y )

%*****************************************************************************80
%
%% doughnut_deriv() evaluates the right hand side of doughnut_ode().
%
%  Discussion:
%
%    The trajectory should remain on a torus.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 October 2025
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John D Cook,
%    Differential equation on a doughnut,
%    https://www.johndcook.com/blog/2025/10/08/diffeq-donut/
%    Posted 08 October 2025.
%
%    Richard Parris,
%    A Three-Dimensional System with Knotted Trajectories. 
%    The American Mathematical Monthly, 
%    Volume 84, Number 6 , June/July 1977, pages 468-469.
%
%  Input:
%
%    real T: the value of the independent variable.
%
%    real Y(M): the values of the dependent variables at time T.
%
%  Output:
%
%    real DYDT(M): the right hand side of the ODE.
%
  [ m, n, ~, ~, ~ ] = doughnut_parameters ( );

  dy1dt = - m * y(2) + n * y(1) * y(3);
  dy2dt =   m * y(1) + n * y(2) * y(3);
  dy3dt =   0.5 * n * ( 1.0 - y(1)^2 - y(2)^2 + y(3)^2 );

  dydt = [ dy1dt; dy2dt; dy3dt ];

  return
end

