GAUSSQUAD

Driver program for Gaussian integration over classical polynomials.

Try also 'help gaussleg, gausslag, gaussherm, gaussgeg, gaussjac'

Contents

User interface

a simple application of 'inputdlg'

entries = {'Function',...
           'Number of points',...
           'parameter a',...
           'parameter b'
          };

default = {'def_fun',...
           '64',...                   % Npts
           '0',...                    % a
           '0'                        % b
          };

AddOpts.Resize  =  'on';
AddOpts.WindowStyle  =  'normal';
AddOpts.Interpreter  =  'tex';

setup = inputdlg(entries, 'parameters', 1, default, AddOpts);

Extracting parameters from 'setup'

f=setup{1};
n = str2num(setup{2});
a = str2num(setup{3});
b = str2num(setup{4});
opt=[a,b];

Choosing the integration rule

The choice is limited to the classical polynomials

'jacobi' for the interval [-1,1] with measure

'hermite' for the interval [-inf,inf]

'gegenbauer' for the interval [-1,1]

'legendre' for the interval [-1,1]

(a special case of Jacobi) 'laguerre' for the interval [0,inf]

The parameters, when needed, are passed through 'a' and 'b'.

selection = {'jacobi','hermite','gegenbauer','legendre','laguerre'};
choice    = menu('Quad rule',selection);

switch choice
 case 1
  [x,w]=GaussJac(n,opt(1),opt(2));
 case 2
  [x,w]=GaussHer(n);
 case 3
  [x,w]=GaussGeg(n,opt(1));
 case 4
  [x,w]=GaussLeg(n);
 case 5
  [x,w]=GaussLag(n,opt(1));

 otherwise
  error('illegal option');
end

F=feval(f,x);

q=sum(w.*F)
Building the companion matrix of Legendre P_n(x)
 
  ... and diagonalizing it:
 
Build Legendre polynomials and Gauss weights
 
Gauss quad rule: int(f(x) dx) ~ sum(w.*f(x))
q =
   3.1962e-16

Author

Enrico Onofri

Dipartimento di Fisica

Universita` di Parma

image(imread('eo_2005_small.jpg'));
axis image
axis('off')