function p1_ex2 ( )

%*****************************************************************************80
%
%% P1_EX2 carries out project 1 exercise 2.
%
%  Licensing:
%
%    This code is distributed under the GNU LGPL license.
%
%  Modified:
%
%    21 March 2019
%
%  Author:
%
%    John Burkardt
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'P1_EX2\n' );
  fprintf ( 1, '  Read dataset R.\n' );
  fprintf ( 1, '  Create order n=3 models using:\n' );
  fprintf ( 1, '  1: 1, x, x^2\n' );
  fprintf ( 1, '  2: 1, x, x^3\n' );
  fprintf ( 1, '  3: 1, x, sin(x)\n' );
%
%  Read data set.
%
  data = load ( 'rising.txt' );
  x = data(:,1);
  y = data(:,2);
  m = length ( x );
%
%  Plot the data.
%
  plot ( x, y, 'bo-', 'linewidth', 3 );
  xlabel ( '<-- X -->' );
  ylabel ( '<-- Y -->' );
  title ( 'The R Dataset', 'fontsize', 16 );
  grid ( 'on' )
  filename = 'p1_ex2_data.png';
  print ( '-dpng', filename );
  fprintf ( 1, '  Graphics saved as "%s"\n', filename );
%
%  1: Set up the linear system A * c = b for [1,x,x^2]:
%
  n = 3;
  A1 = [ x.^0, x.^1, x.^2 ];
  b1 = y;
  c1 = pinv ( A1 ) * b1;
  r1 = A1 * c1 - b1;
%
%  2: Set up the linear system A * c = b for [1,x,x^3]:
%
  n = 3;
  A2 = [ x.^0, x.^1, x.^3 ];
  b2 = y;
  c2 = pinv ( A2 ) * b2;
  r2 = A2 * c2 - b2;
%
%  3: Set up the linear system A * c = b for [1,x,sin(x)]:
%
  n = 3;
  A3 = [ x.^0, x.^1, sin(x) ];
  b3 = y;
  c3 = pinv ( A3 ) * b3;
  r3 = A3 * c3 - b3;
%
%  Tabulate results.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, '  TABLE 2:\n' );
  fprintf ( 1, '  Method  ----------------c-------------     rms(r)\n' );
  fprintf ( 1, '\n' );
  fprintf ( 1, '     1    %8.5g  %8.5g  %8.5g  %8.5g\n', c1, rms ( r1 ) );
  fprintf ( 1, '     2    %8.5g  %8.5g  %8.5g  %8.5g\n', c2, rms ( r2 ) );
  fprintf ( 1, '     3    %8.5g  %8.5g  %8.5g  %8.5g\n', c3, rms ( r3 ) );
%
%  Terminate.
%
  fprintf ( 1, '\n' );
  fprintf ( 1, 'P1_EX2\n' );
  fprintf ( 1, '  Normal end of execution.\n' );

  return
end