function vanderpol_midpoint ( n )

%*****************************************************************************80
%
%% vanderpol_midpoint() calls midpoint() to solve the van der Pol ODE.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    24 April 2021
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'vanderpol_midpoint():\n' );
  fprintf ( 1, '  Use midpoint() to solve the van der Pol ODE.\n' );
%
%  Get parameter values.
%
  [ mu, t0, y0, tstop ] = vanderpol_parameters ( );

  f = @ vanderpol_deriv;
  tspan = [ t0, tstop ];
  
  [ t, y ] = midpoint ( f, tspan, y0, n );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Number of equal steps = %d\n', n );
%
%  Time plot of y(t), y'(t).
%
  figure ( 1 );
  plot ( t, y, 'linewidth', 3 );
  grid ( 'on' );
  xlabel ( '<-- T -->' );
  ylabel ( '<-- Y(T) -->' );
  s = sprintf ( 'van der Pol midpoint, \\mu = %g', mu );
  title ( s );
  legend ( 'y(t)', 'y''(t)' );
  filename = 'vanderpol_midpoint_plot.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  Phase plot.
%
  figure ( 2 );
  clf ( );
  hold ( 'on' );
    plot ( y(:,1), y(:,2), 'linewidth', 3 );
    plot ( y(1,1), y(1,2), 'g.', 'markersize', 40 );
    plot ( y(end,1), y(end,2), 'r.', 'markersize', 30 );
  hold ( 'off' );
  axis ( 'equal' );
  grid ( 'on' );
  xlabel ( '<-- Y(T) -->' );
  ylabel ( '<-- Y''(T) -->' );
  s = sprintf ( 'van der Pol midpoint phase plot, \\mu = %g', mu );
  title ( s );
  filename = 'vanderpol_midpoint_phase.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );

  return
end

