function double_well_ode45 ( )

%*****************************************************************************80
%
%% double_well_ode45() uses ode45() on the double_well ODE.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    09 June 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'double_well_ode45()\n' );
  fprintf ( 1, '  Solve the double_well ODE using ode45().\n' );

  [ t0, y0, tstop ] = double_well_parameters ( );

  f = @ double_well_deriv;
  tspan = [ t0, tstop ];

  [ t, y ] = ode45 ( f, tspan, y0 );
  n = length ( t );
  fprintf ( 1, '  Number of steps taken was %d\n', n );

  clf ( )
  hold ( 'on' );
    plot ( t, y(:,1), 'r-', 'linewidth', 3 );
    plot ( t, y(:,2), 'b-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- t -->' );
  ylabel ( '<-- y(t) -->' );
  title ( ' double well, ode45, time plot' );
  legend ( 'Q', 'P' );
  filename = 'double_well_ode45_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  clf ( )
  plot ( y(:,1), y(:,2), 'r-', 'linewidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Q -->' );
  ylabel ( '<-- P -->' );
  title ( ' double well, ode45, phase plot' );
  filename = 'double_well_ode45_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  q = y(:,1);
  p = y(:,2);
  h = double_well_conserved ( q, p );

  clf ( );
  hold ( 'on' );
    plot ( t, h, 'r-', 'LineWidth', 3 );
    plot ( [ t0, tstop ], [ h(1), h(1) ], 'b--', 'LineWidth', 3 );
    plot ( [ t0, tstop ], [ 0.0, 0.0 ], 'k--', 'LineWidth', 3 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- H(t) -->' );
  title ( 'double well, ode45, conservation' );
  filename = 'double_well_ode45_conservation.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

