function tough_midpoint ( n )

%*****************************************************************************80
%
%% tough_midpoint tests tough_ode using midpoint().
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 April 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'tough_midpoint:\n' );
  fprintf ( 1, '  Test tough_ode using midpoint.\n' );

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

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

  [ t, y ] = midpoint ( f, tspan, y0, n );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of equal steps = %d\n', n );

  te = linspace ( t0, tstop, 101 );
  ye = tough_exact ( te );
%
%  Plot y1.
%
  figure ( 1 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,1), 'r-', 'linewidth', 2 );
    plot ( te, ye(:,1), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Y1(t) -->' );
  title ( 'tough ODE, midpoint(): y1' );
  legend ( 'midpoint', 'exact' );
  filename = 'tough_midpoint_y1.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot y2.
%
  figure ( 2 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,2), 'r-', 'linewidth', 2 );
    plot ( te, ye(:,2), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Y2(t) -->' );
  title ( 'tough ODE, y2: midpoint' );
  legend ( 'midpoint', 'exact' );
  filename = 'tough_midpoint_y2.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot y3.
%
  figure ( 3 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,3), 'r-', 'linewidth', 2 );
    plot ( te, ye(:,3), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Y3(t) -->' );
  title ( 'tough ODE, y3: midpoint' );
  legend ( 'midpoint', 'exact' );
  filename = 'tough_midpoint_y3.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );
%
%  Plot y4.
%
  figure ( 4 );
  clf ( );
  hold ( 'on' );
    plot ( t, y(:,4), 'r-', 'linewidth', 2 );
    plot ( te, ye(:,4), 'b-', 'linewidth', 2 );
  hold ( 'off' );
  grid ( 'on' );
  xlabel ( '<-- Time -->' );
  ylabel ( '<-- Y4(t) -->' );
  title ( 'tough ODE, y4: midpoint' );
  legend ( 'midpoint', 'exact' );
  filename = 'tough_midpoint_y4.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved in "%s"\n', filename );

  return
end

