function lindberg_resid_test ( )

%*****************************************************************************80
%
%% lindberg_resid_test() computes residuals of the Lindberg ODE exact solution.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    11 May 2024
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'lindberg_resid_test():\n' );
  fprintf ( 1, '  Compute the residuals of the exact solution components\n' );
  fprintf ( 1, '  of the Lindberg ODE.\n' );
  fprintf ( 1, '  Report the reslative errors.\n' );

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

  n = 21;
  t = linspace ( t0, tstop, n );

  [ y, dydt ] = lindberg_exact ( t );
  r = lindberg_resid ( t, y, dydt );
%
%  Limit magnitude of y1 and y2.
%
  for i = 1 : n
    for j = 1 : 4
      y(i,j) = min ( y(i,j), 1.0E+6 );
      y(i,j) = max ( y(i,j), -1.0E+6 );
    end
  end

  for i = 1 : n
    for j = 1 : 4
      if ( abs ( y(i,j) < eps ) )
        y(i,j) = 0.0;
      end
    end
  end
%
%  Compute relative error.
%
  e = r ./ y;
%
%  If e is NAN, reset e to -1, and reset r to 0.
%  Then if r is 0, reset e to 0.
%
  TF = isnan ( e );
  r(TF) = 0.0;
  e(TF) = -1.0;

  TF = find ( ~r );
  e(TF) = 0.0;

  fprintf ( 1, '\n' );
  fprintf ( 1, '  Relative error in Y1, Y2, Y3, Y4 at selected T values:\n' );

  disp ( e );

  return
end
