function [ n1, n2, q, r ] = legendre_dot_product ( i, j )

%*****************************************************************************80
%
%% legendre_dot_product: dot product of the i and j Legendre polynomials.
%
%  Input:
%
%    integer i, j: the indices of the two polynomials.
%
%  Output:
%
%    real n1, n2: the L2 norms of Pi and Pj over [-1,+1].
%
%    real q: the L2 dot product of Pi and Pj over [-1,+1];
%
%    real r: the "relative" L2 dot product of Pi and Pj over [-1,+1].
%
  q = integral ( @(x) legendre_value(i,x) .* legendre_value(j,x), -1.0, +1.0 );

  ni = sqrt ( integral ( @(x) (legendre_value(i,x)).^2, -1.0, +1.0 ) );
  nj = sqrt ( integral ( @(x) (legendre_value(j,x)).^2, -1.0, +1.0 ) );
  r = q / ni / nj;
  angle = acos ( r ) * 180.0 / pi;

  fprintf ( '\n' );
  fprintf ( ' ||P%d(x)|| = %g\n', i, ni );
  fprintf ( ' ||P%d(x)|| = %g\n', j, nj );
  fprintf ( ' <P%d(x),P%d(x)> = %g\n', i, j, q );
  fprintf ( ' <P%d(x),P%d(x)> / ||P%d(x)|| / ||P%d(x)|| = %g\n', i, j, i, j, r );
  fprintf ( ' Angle = %g degrees\n', angle );

  return
end

