function expsin_rk1_higher ( n )

%*****************************************************************************80
%
%% expsin_rk1_higher estimates error by comparing rk1 and rk2.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    28 September 2020
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer N: the number of steps to take.
%
  if ( nargin < 1 )
    n = 20;
  end

  fprintf ( 1, '\n' );
  fprintf ( 1, 'expsin_rk1_higher:\n' );
  fprintf ( 1, '  Estimate ODE approximation error by using higher order.\n' );

  dydt = @ expsin_deriv;
  t0 = 0.0;
  tstop = 10.0;
  tspan = [ t0, tstop ];
  y0 = 1.0;

  [ t, y1 ] = rk1 ( dydt, tspan, y0, n );

  [ t, y2 ] = rk2 ( dydt, tspan, y0, n );

  y = expsin_solution ( t );

  e =  y1 - y;
  e2 = y1 - y2;

  e_norm  = rms ( e );
  e2_norm = rms ( e2 );

  tplot = linspace ( t0, tstop, 101 );
  yplot = expsin_solution ( tplot );
  plot ( t, y1, 'ro', t, y2, 'b+', tplot, yplot, 'k-', ...
    'markersize', 15, 'linewidth', 3 );
  grid ( 'on' );
  s = sprintf ( 'Compare expsin rk1 and rk2 solutions with n = %d', n );
  title ( s );
  filename = sprintf ( 'expsin_rk1_higher_%d.png', n );
  print ( '-dpng', filename );

  plot ( [t0,tstop], [0.0,0.0], 'k--', t, e2, 'r-', t, e, 'k-', 'linewidth', 3 );
  grid ( 'on' );
  s = sprintf ( 'expsin rk1-rk2 estimated error using %d', n );
  title ( s );
  legend ( 'Zero error', 'rk1-rk2 error', 'Exact error', ...
    'location', 'north' );
  filename = sprintf ( 'expsin_rk1_higher_error_%d.png', n );
  print ( '-dpng', filename );
%
%  Report error estimates for whole solution, and at final point.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  Estimated RMS error = %g\n', e2_norm );
  fprintf ( 1, '  Exact     RMS error = %g\n', e_norm );

  fprintf ( 1, '\n' );
  fprintf ( 1, '  At the point t         = %g,\n', tstop );
  fprintf ( 1, '  Y estimate             = %g\n', y1(n+1) );
  fprintf ( 1, '  Y double step estimate = %g\n', y2(n+1) );
  fprintf ( 1, '  Y exact value          = %g\n', y(n+1) );
  fprintf ( 1, '  Y error estimate       = %g\n', y2(n+1) - y1(n+1) );
  fprintf ( 1, '  Y exact error          = %g\n', y(n+1)  - y1(n+1) );

  return
end

