function wave_midpoint ( )

%*****************************************************************************80
%
%% wave_midpoint() tests wave_ode using midpoint().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    20 December 2020
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'wave_midpoint():\n' );
  fprintf ( 1, '  Test wave_ode() using midpoint().\n' );
%
%  Get the parameters.
%
  [ xmin, xmax, nx, dx, c, t0, tstop ] = wave_parameters ( );
  x = linspace ( xmin, xmax, nx );
%
%  Under periodic boundary conditions, our integration process is simple.
%
  f = @ wave_deriv;
  tspan = [ t0, tstop ];
  w0 = wave_init ( );
  n = 100;

  [ t, w ] = midpoint ( f, tspan, w0, n );
%
%  Plot the energy.
%
  we = wave_exact ( t0 );
  he = wave_conserved ( we );

  h = wave_conserved ( w );

  figure ( 4 );
  clf ( );
  hold ( 'on' );
    plot ( t, h, 'ro', 'linewidth', 2 );
    plot ( [t0,tstop], [ he, he ], 'b--', 'linewidth', 2 );
    plot ( [t0,tstop], [ 0.0, 0.0 ], 'k--', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Energy -->' );
  title ( 'wave midpoint: energy' );
  legend ( 'Computed energy', 'Exact energy', 'Zero energy', ...
    'Location', 'South' );
  filename = 'wave_midpoint_energy.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
  close ( 4 );

  return
end

