No BSD License  

Highlights from
gaussq

4.0

4.0 | 6 ratings Rate this file 4 Downloads (last 30 days) File Size: 6.44 KB File ID: #32

gaussq

by Per A. Brodtkorb

 

12 Jul 1999 (Updated 28 Nov 2005)

Numerically evaluates a integral using a Gauss quadrature.

| Watch this File

File Information
Description

CALL:
  [int, tol] = gaussq('Fun',A,B,[reltol wfun],[trace,gn],p1,p2,....)
  [int, tol] = gaussq('Fun',A,B,[reltol wfun],[trace,gn],alpha,p1,p2,....)
  [int, tol] = gaussq('Fun',A,B,[reltol wfun],[trace,gn],alpha,beta,p1,p2,....)

       int = evaluated integral
       tol = absolute tolerance abs(int-intold)
       Fun = inline object, function handle or a function string.
             The function may depend on the parameters alpha and beta.
       A,B = lower and upper integration limits, respectively.
    reltol = relative tolerance (default 1e-3).
      wfun = integer defining the weight function:
         1 p(x)=1 a =-1, b = 1 Legendre (default)
         2 p(x)=1/sqrt((x-a)*(b-x)), a =-1, b = 1 Chebyshev of the
                    first kind
         3 p(x)=sqrt((x-a)*(b-x)), a =-1, b = 1 Chebyshev of the
                    second kind
         4 p(x)=sqrt((x-a)/(b-x)), a = 0, b = 1
         5 p(x)=1/sqrt(b-x), a = 0, b = 1
         6 p(x)=sqrt(b-x), a = 0, b = 1
         7 p(x)=(x-a)^alpha*(b-x)^beta a =-1, b = 1 Jacobi
                    alpha, beta >-1 (default alpha=beta=0)
         8 p(x)=x^alpha*exp(-x) a = 0, b = inf generalized Laguerre
         9 p(x)=exp(-x^2) a =-inf, b = inf Hermite
        10 p(x)=1 a =-1, b = 1 Legendre (slower than 1)

   trace = for non-zero TRACE traces the function evaluations
              with a point plot of the integrand (default 0).
      gn = number of base points and weight points to start the
            integration with (default 2).
p1,p2,...= coefficients to be passed directly to function Fun:
                  G = Fun(x,p1,p2,...).

 GAUSSQ Numerically evaluates a integral using a Gauss quadrature.
 The Quadrature integrates a (2m-1)th order polynomial exactly and the
 integral is of the form
              b
             Int (p(x)* Fun(x)) dx
              a
 GAUSSQ accept integration limits A, B and coefficients P1,P2,...
 as matrices or scalars and the result INT is the common size of A, B
 and P1,P2,....

 Examples :% a) integration of x.^2 from 0 to 2 and from 1 to 4
           % b) integration of x^2*exp(-x) from zero to infinity

    gaussq('(x.^2)',[0 1],[2 4]) % a)
    gaussq('(1)',0,inf,[1e-3 8],[],2) % b)
    gaussq('(x.^2)',0,inf,[1e-3 8],[],0) % b)

MATLAB release MATLAB 5.3 (R11)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
14 Sep 2003 Slobodan Babic  
11 Dec 2003 Arnold Yuan

Very nice! but you have to use the old-version function handle '' rather than @ in Matlab 6 or higher

21 Dec 2003 Faisal Saeed  
23 Jun 2004 VĂ­ctor Castillo

How can i calculate the integral

3*(x.^2)*exp(x)
for a=-2, b=1, with n=2

18 Apr 2006 John D'Errico

If I ever found myself trapped on a desert island and I could only take one (1-d) Gaussian quadrature code with me, this would be it.

28 Dec 2006 Alex Minovich

Long and buggy!

Please login to add a comment or rating.
Updates

modifying description

28 Nov 2005

Gaussq is now updated to also allow integration of function handles or inline objects.
Global variables are changed to persistent to make the function more robust.

Tag Activity for this File
Tag Applied By Date/Time
integration Per A. Brodtkorb 22 Oct 2008 06:30:48
gauss Per A. Brodtkorb 22 Oct 2008 06:30:48
quadrature Per A. Brodtkorb 22 Oct 2008 06:30:48
integrate Per A. Brodtkorb 22 Oct 2008 06:30:48
polynomial Per A. Brodtkorb 22 Oct 2008 06:30:48

Contact us at files@mathworks.com