function y = doughnut_exact ( t )

%*****************************************************************************80
%
%% doughnut_exact(): exact solution of doughnut ODE.
%
%  Discussion:
%
%    The formula assumes that t0 = 0.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 October 2025
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John D Cook,
%    Rational solution to the Korteweg-De Vries equation,
%    13 November 2023,
%    https://www.johndcook.com/blog/2023/11/13/rational-kdv/
%
%  Input:
%
%    real t(:): the time.
%
%  Output:
%
%    real y(:,3): the exact solution at time t.
%

%
%  Force t to be a column vector.
%
  t = t(:);
  tnum = length ( t );

  [ m, n, ~, y0, ~ ] = doughnut_parameters ( );

  y = zeros ( tnum, 3 );

  a = y0(1);
  b = y0(2);
  c = y0(3);

  delta = 1.0 + a^2 + b^2 + c^2;
  
  y(:,1) = ( 2.0 * a * cos ( m * t ) - 2.0 * b * sin ( m * t ) ) ...
         ./ ( delta - 2.0 * c * sin ( n * t ) + ( 2.0 - delta ) * cos ( n * t ) );

  y(:,2) = ( 2.0 * a * sin ( m * t ) + 2.0 * b * cos ( m * t ) ) ...
         ./ ( delta - 2.0 * c * sin ( n * t ) + ( 2.0 - delta ) * cos ( n * t ) );

  y(:,3) = ( 2.0 * c * cos ( n * t ) + ( 2.0 - delta ) * sin ( n * t ) ) ...
         ./ ( delta - 2.0 * c * sin ( n * t ) + ( 2.0 - delta ) * cos ( n * t ) );

  return
end

