function dydt = three_body_deriv ( t, y )

%*****************************************************************************80
%
%% three_body_deriv() returns the right hand side of three_body_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 November 2020
%
%  Author:
%
%    Original MATLAB version by Dominik Gruntz, Joerg Waldvogel.
%    This MATLAB version by John Burkardt.
%
%  Reference:
%
%    Dominik Gruntz, Joerg Waldvogel,
%    Orbits in the Planar Three-Body Problem,
%    Walter Gander, Jiri Hrebicek, editors,
%    Solving Problems in Scientific Computing using Maple and Matlab,
%    Springer, 1997,
%    ISBN: 3-540-61793-0,
%    LC: Q183.9.G36.
%
%  Input:
%
%    real T, the current time.
%
%    real Y(12), the current solution.
%
%  Output:
%
%    real DYDT(12), the derivatives of the current solution.
%
  [ m0, m1, m2, t0, y0, tstop ] = three_body_parameters ( );

  y = y(:);

  x0 = y(1:2);
  x1 = y(5:6);
  x2 = y(9:10);

  d0 = ( x2 - x1 ) / norm ( x2 - x1 )^3;
  d1 = ( x0 - x2 ) / norm ( x0 - x2 )^3;
  d2 = ( x1 - x0 ) / norm ( x1 - x0 )^3;

  dydt = zeros ( 12, 1 );

  dydt(1:2) = y(3:4);
  dydt(3:4) = m1 * d2 - m2 * d1;
  dydt(5:6) = y(7:8);
  dydt(7:8) = m2 * d0 - m0 * d2;
  dydt(9:10) = y(11:12);
  dydt(11:12) = m0 * d1 - m1 * d0;

  return
end
