function dydt = blood_pressure_deriv ( t, y )

%*****************************************************************************80
%
%% blood_pressure_deriv() evaluates the derivative for blood_pressure_ode().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    18 March 2022
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    real T, Y: the arguments of the derivative.
%
%  Output:
%
%    real DYDT: the value of the derivative.
%
%  Local:
%
%    real CA: the compliance.
%
%    real RS: the resistance.
%
  [ pdia, psys, pulse, q, told, t0, y0, tstop ] = blood_pressure_parameters ( );

  T = 1.0 / pulse;
  b1 = floor ( ( told - t0 ) / T );
  b2 = floor ( ( t - t0 )    / T );

  if ( b1 == b2 )
    ca = blood_pressure_compliance ( );
    rs = blood_pressure_resistance ( );
    dydt = - y / ca / rs;
%
%  This assumes b2 = b1 + 1.
%
  else
    dydt = ( psys - y ) / ( t - told );
  end
%
%  Remember the value of time.
%
  told = t;
  blood_pressure_parameters ( pdia, psys, pulse, q, told, t0, y0, tstop );

  return
end
