function dydt = spring_double_deriv ( t, y )

%*****************************************************************************80
%
%% spring_double deriv() returns the right hand side of spring_double_ode().
%
%  Discussion:
%
%    Spring #1 is suspended from a fixed support, has mass m1 and 
%    spring constant k1.
%
%    Spring #2 is suspended from spring #1, has mass m2 and spring
%    constant k2.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    04 March 2021
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    John D Cook,
%    A stiffening spring,
%    https://www.johndcook.com/blog/2021/03/04/a-stiffening-spring/
%
%    K E Clark, S Hill,
%    The Effects of a Stiffening Spring,
%    College Mathematics Journal,
%    Volume 30, Number 5, November 1999, pages 379-382.
%
%  Input:
%
%    real T, the current time.
%
%    real Y(4), the current state values.
%
%  Output:
%
%    real dydt(4), the time derivatives of the current state values.
%
  [ m1, m2, k1, k2, t0, y0, tstop ] = spring_double_parameters ( );

  u1 = y(1);
  v1 = y(2);
  u2 = y(3);
  v2 = y(4);

  du1dt = v1;
  dv1dt = ( - k1 * u1 + k2 * ( u2 - u1 ) ) / m1;
  du2dt = v2;
  dv2dt = (           - k2 * ( u2 - u1 ) ) / m2;

  dydt = [ du1dt; dv1dt; du2dt; dv2dt ];

  return
end

