function gyroscope_ode23 ( )

%*****************************************************************************80
%
%% gyroscope_ode23() solves gyroscope_ode() using ode23().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    19 August 2024
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'gyroscope_ode23():\n' );
  fprintf ( 1, '  Solve gyroscope_ode() using ode23().\n' );

  [ A1, A2, A3, m, t0, y0, tstop ] = gyroscope_parameters ( );

  f = @ gyroscope_deriv;
  tspan = [ t0, tstop ];
  [ t, y ] = ode23 ( f, tspan, y0 );

  n = size ( t, 1 );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of variable size steps = %d\n', n );
%
%  Plot psi, theta, phi.
%
  y(:,1) = mod ( y(:,1) + pi, 2.0 * pi ) - pi;
  y(:,2) = mod ( y(:,2) + pi, 2.0 * pi ) - pi;
  y(:,3) = mod ( y(:,3) + pi, 2.0 * pi ) - pi;

  figure ( 1 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,1), 'linewidth', 2 );
    plot ( t, y(:,2), 'linewidth', 2 );
    plot ( t, y(:,3), 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- radians -->' );
  title ( 'gyroscope\_ode(): ode23: \psi(t), \theta(t), \phi(t)' );
  legend ( '\psi', '\theta', '\phi' );
  filename = 'gyroscope_ode23_angles.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot rotation.
%
  figure ( 2 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,4), 'linewidth', 2 );
    plot ( t, y(:,5), 'linewidth', 2 );
    plot ( t, y(:,6), 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- rotation speed -->' );
  title ( 'gyroscope\_ode(): ode23: rotation rates' );
  legend ( '\omega_1', '\omega_2', '\omega_3' );
  filename = 'gyroscope_ode23_rotation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );

  return
end

