Code covered by the BSD License  

Highlights from
slatec

from slatec by Ben Barrowes
The slatec library converted into matlab functions.

[f,bound,inf,epsabs,epsrel,limit,result,abserr,neval,ier,alist,blist,rlist,elist,iord,last]=qagie(f,bound,inf,epsabs,epsrel,limit,result,abserr,neval,ier,alist,blist,rlist,elist,iord,last);
function [f,bound,inf,epsabs,epsrel,limit,result,abserr,neval,ier,alist,blist,rlist,elist,iord,last]=qagie(f,bound,inf,epsabs,epsrel,limit,result,abserr,neval,ier,alist,blist,rlist,elist,iord,last);
%***BEGIN PROLOGUE  QAGIE
%***PURPOSE  The routine calculates an approximation result to a given
%            integral   I = Integral of F over (BOUND,+INFINITY)
%                    or I = Integral of F over (-INFINITY,BOUND)
%                    or I = Integral of F over (-INFINITY,+INFINITY),
%                    hopefully satisfying following claim for accuracy
%                    ABS(I-RESULT).LE.MAX(EPSABS,EPSREL*ABS(I))
%***LIBRARY   SLATEC (QUADPACK)
%***CATEGORY  H2A3A1, H2A4A1
%***TYPE      SINGLE PRECISION (QAGIE-S, DQAGIE-D)
%***KEYWORDS  AUTOMATIC INTEGRATOR, EXTRAPOLATION, GENERAL-PURPOSE,
%             GLOBALLY ADAPTIVE, INFINITE INTERVALS, QUADPACK,
%             QUADRATURE, TRANSFORMATION
%***AUTHOR  Piessens, Robert
%             Applied Mathematics and Programming Division
%             K. U. Leuven
%           de Doncker, Elise
%             Applied Mathematics and Programming Division
%             K. U. Leuven
%***DESCRIPTION
%
% Integration over infinite intervals
% Standard fortran subroutine
%
%            F      - Real
%                     function subprogram defining the integrand
%                     function F(X). The actual name for F needs to be
%                     declared E X T E R N A L in the driver program.
%
%            BOUND  - Real
%                     Finite bound of integration range
%                     (has no meaning if interval is doubly-infinite)
%
%            INF    - Real
%                     Indicating the kind of integration range involved
%                     INF = 1 corresponds to  (BOUND,+INFINITY),
%                     INF = -1            to  (-INFINITY,BOUND),
%                     INF = 2             to (-INFINITY,+INFINITY).
%
%            EPSABS - Real
%                     Absolute accuracy requested
%            EPSREL - Real
%                     Relative accuracy requested
%                     If  EPSABS.LE.0
%                     and EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
%                     the routine will end with IER = 6.
%
%            LIMIT  - Integer
%                     Gives an upper bound on the number of subintervals
%                     in the partition of (A,B), LIMIT.GE.1
%
%         ON RETURN
%            RESULT - Real
%                     Approximation to the integral
%
%            ABSERR - Real
%                     Estimate of the modulus of the absolute error,
%                     which should equal or exceed ABS(I-RESULT)
%
%            NEVAL  - Integer
%                     Number of integrand evaluations
%
%            IER    - Integer
%                     IER = 0 Normal and reliable termination of the
%                             routine. It is assumed that the requested
%                             accuracy has been achieved.
%                   - IER.GT.0 Abnormal termination of the routine. The
%                             estimates for result and error are less
%                             reliable. It is assumed that the requested
%                             accuracy has not been achieved.
%            ERROR MESSAGES
%                     IER = 1 Maximum number of subdivisions allowed
%                             has been achieved. One can allow more
%                             subdivisions by increasing the value of
%                             LIMIT (and taking the according dimension
%                             adjustments into account).  However, if
%                             this yields no improvement it is advised
%                             to analyze the integrand in order to
%                             determine the integration difficulties.
%                             If the position of a local difficulty can
%                             be determined (e.g. SINGULARITY,
%                             DISCONTINUITY within the interval) one
%                             will probably gain from splitting up the
%                             interval at this point and calling the
%                             integrator on the subranges. If possible,
%                             an appropriate special-purpose integrator
%                             should be used, which is designed for
%                             handling the type of difficulty involved.
%                         = 2 The occurrence of roundoff error is
%                             detected, which prevents the requested
%                             tolerance from being achieved.
%                             The error may be under-estimated.
%                         = 3 Extremely bad integrand behaviour occurs
%                             at some points of the integration
%                             interval.
%                         = 4 The algorithm does not converge.
%                             Roundoff error is detected in the
%                             extrapolation table.
%                             It is assumed that the requested tolerance
%                             cannot be achieved, and that the returned
%                             result is the best which can be obtained.
%                         = 5 The integral is probably divergent, or
%                             slowly convergent. It must be noted that
%                             divergence can occur with any other value
%                             of IER.
%                         = 6 The input is invalid, because
%                             (EPSABS.LE.0 and
%                              EPSREL.LT.MAX(50*REL.MACH.ACC.,0.5D-28),
%                             RESULT, ABSERR, NEVAL, LAST, RLIST(1),
%                             ELIST(1) and IORD(1) are set to zero.
%                             ALIST(1) and BLIST(1) are set to 0
%                             and 1 respectively.
%
%            ALIST  - Real
%                     Vector of dimension at least LIMIT, the first
%                      LAST  elements of which are the left
%                     end points of the subintervals in the partition
%                     of the transformed integration range (0,1).
%
%            BLIST  - Real
%                     Vector of dimension at least LIMIT, the first
%                      LAST  elements of which are the right
%                     end points of the subintervals in the partition
%                     of the transformed integration range (0,1).
%
%            RLIST  - Real
%                     Vector of dimension at least LIMIT, the first
%                      LAST  elements of which are the integral
%                     approximations on the subintervals
%
%            ELIST  - Real
%                     Vector of dimension at least LIMIT,  the first
%                     LAST elements of which are the moduli of the
%                     absolute error estimates on the subintervals
%
%            IORD   - Integer
%                     Vector of dimension LIMIT, the first K
%                     elements of which are pointers to the
%                     error estimates over the subintervals,
%                     such that ELIST(IORD(1)), ..., ELIST(IORD(K))
%                     form a decreasing sequence, with K = LAST
%                     If LAST.LE.(LIMIT/2+2), and K = LIMIT+1-LAST
%                     otherwise
%
%            LAST   - Integer
%                     Number of subintervals actually produced
%                     in the subdivision process
%
%***REFERENCES  (NONE)
%***ROUTINES CALLED  QELG, QK15I, QPSRT, R1MACH
%***REVISION HISTORY  (YYMMDD)
%   800101  DATE WRITTEN
%   890531  Changed all specific intrinsics to generic.  (WRB)
%   890831  Modified array declarations.  (WRB)
%   890831  REVISION DATE from Version 3.2
%   891214  Prologue converted to Version 4.0 format.  (BAB)
%***end PROLOGUE  QAGIE
%
persistent a1 a2 abseps area area1 area12 area2 b1 b2 boun correc defab1 defab2 defabs dres epmach erlarg erlast errbnd errmax erro12 error1 error2 errsum ertest extrap gt id ierro iroff1 iroff2 iroff3 jupbnd k ksgn ktmin maxerr noext nres nrmax numrl2 oflow res3la resabs reseps rlist2 small uflow ; 

if isempty(abseps), abseps=0; end;
if isempty(area), area=0; end;
if isempty(area1), area1=0; end;
if isempty(area12), area12=0; end;
if isempty(area2), area2=0; end;
if isempty(a1), a1=0; end;
if isempty(a2), a2=0; end;
if isempty(boun), boun=0; end;
if isempty(b1), b1=0; end;
if isempty(b2), b2=0; end;
if isempty(correc), correc=0; end;
if isempty(defabs), defabs=0; end;
if isempty(defab1), defab1=0; end;
if isempty(defab2), defab2=0; end;
if isempty(dres), dres=0; end;
if isempty(epmach), epmach=0; end;
if isempty(erlarg), erlarg=0; end;
if isempty(erlast), erlast=0; end;
if isempty(errbnd), errbnd=0; end;
if isempty(errmax), errmax=0; end;
if isempty(error1), error1=0; end;
if isempty(error2), error2=0; end;
if isempty(erro12), erro12=0; end;
if isempty(errsum), errsum=0; end;
if isempty(ertest), ertest=0; end;
if isempty(oflow), oflow=0; end;
if isempty(resabs), resabs=0; end;
if isempty(reseps), reseps=0; end;
if isempty(res3la), res3la=zeros(1,3); end;
if isempty(rlist2), rlist2=zeros(1,52); end;
if isempty(small), small=0; end;
if isempty(uflow), uflow=0; end;
if isempty(id), id=0; end;
if isempty(ierro), ierro=0; end;
if isempty(iroff1), iroff1=0; end;
if isempty(iroff2), iroff2=0; end;
if isempty(iroff3), iroff3=0; end;
if isempty(jupbnd), jupbnd=0; end;
if isempty(k), k=0; end;
if isempty(ksgn), ksgn=0; end;
if isempty(ktmin), ktmin=0; end;
if isempty(maxerr), maxerr=0; end;
if isempty(nres), nres=0; end;
if isempty(nrmax), nrmax=0; end;
if isempty(numrl2), numrl2=0; end;
if isempty(gt), gt=zeros(1,3); end;
if isempty(extrap), extrap=false; end;
if isempty(noext), noext=false; end;
%
alist_shape=size(alist);alist=reshape(alist,1,[]);
blist_shape=size(blist);blist=reshape(blist,1,[]);
elist_shape=size(elist);elist=reshape(elist,1,[]);
iord_shape=size(iord);iord=reshape(iord,1,[]);
rlist_shape=size(rlist);rlist=reshape(rlist,1,[]);
%
%
%            THE DIMENSION OF RLIST2 IS DETERMINED BY THE VALUE OF
%            LIMEXP IN SUBROUTINE QELG.
%
%
%            LIST OF MAJOR VARIABLES
%            -----------------------
%
%           ALIST     - LIST OF LEFT END POINTS OF ALL SUBINTERVALS
%                       CONSIDERED UP TO NOW
%           BLIST     - LIST OF RIGHT END POINTS OF ALL SUBINTERVALS
%                       CONSIDERED UP TO NOW
%           RLIST(I)  - APPROXIMATION TO THE INTEGRAL OVER
%                       (ALIST(I),BLIST(I))
%           RLIST2    - ARRAY OF DIMENSION AT LEAST (LIMEXP+2),
%                       CONTAINING THE PART OF THE EPSILON TABLE
%                       WHICH IS STILL NEEDED FOR FURTHER COMPUTATIONS
%           ELIST(I)  - ERROR ESTIMATE APPLYING TO RLIST(I)
%           MAXERR    - POINTER TO THE INTERVAL WITH LARGEST ERROR
%                       ESTIMATE
%           ERRMAX    - ELIST(MAXERR)
%           ERLAST    - ERROR ON THE INTERVAL CURRENTLY SUBDIVIDED
%                       (BEFORE THAT SUBDIVISION HAS TAKEN PLACE)
%           AREA      - SUM OF THE INTEGRALS OVER THE SUBINTERVALS
%           ERRSUM    - SUM OF THE ERRORS OVER THE SUBINTERVALS
%           ERRBND    - REQUESTED ACCURACY MAX(EPSABS,EPSREL*
%                       ABS(RESULT))
%           *****1    - VARIABLE FOR THE LEFT SUBINTERVAL
%           *****2    - VARIABLE FOR THE RIGHT SUBINTERVAL
%           LAST      - INDEX FOR SUBDIVISION
%           NRES      - NUMBER OF CALLS TO THE EXTRAPOLATION ROUTINE
%           NUMRL2    - NUMBER OF ELEMENTS CURRENTLY IN RLIST2. IF AN
%                       APPROPRIATE APPROXIMATION TO THE COMPOUNDED
%                       INTEGRAL HAS BEEN OBTAINED, IT IS PUT IN
%                       RLIST2(NUMRL2) AFTER NUMRL2 HAS BEEN INCREASED
%                       BY ONE.
%           SMALL     - LENGTH OF THE SMALLEST INTERVAL CONSIDERED UP
%                       TO NOW, MULTIPLIED BY 1.5
%           ERLARG    - SUM OF THE ERRORS OVER THE INTERVALS LARGER
%                       THAN THE SMALLEST INTERVAL CONSIDERED UP TO NOW
%           EXTRAP    - LOGICAL VARIABLE DENOTING THAT THE ROUTINE
%                       IS ATTEMPTING TO PERFORM EXTRAPOLATION. I.E.
%                       BEFORE SUBDIVIDING THE SMALLEST INTERVAL WE
%                       TRY TO DECREASE THE VALUE OF ERLARG.
%           NOEXT     - LOGICAL VARIABLE DENOTING THAT EXTRAPOLATION
%                       IS NO LONGER ALLOWED (truemlv-VALUE)
%
%            MACHINE DEPENDENT CONSTANTS
%            ---------------------------
%
%           EPMACH IS THE LARGEST RELATIVE SPACING.
%           UFLOW IS THE SMALLEST POSITIVE MAGNITUDE.
%           OFLOW IS THE LARGEST POSITIVE MAGNITUDE.
%
%***FIRST EXECUTABLE STATEMENT  QAGIE
[epmach ]=r1mach(4);
%
%           TEST ON VALIDITY OF PARAMETERS
%           -----------------------------
%
ier = 0;
neval = 0;
last = 0;
result = 0.0e+00;
abserr = 0.0e+00;
alist(1) = 0.0e+00;
blist(1) = 0.1e+01;
rlist(1) = 0.0e+00;
elist(1) = 0.0e+00;
iord(1) = 0;
if( epsabs<=0.0e+00 && epsrel<max(0.5e+02.*epmach,0.5e-14) )
ier = 6;
end;
if( ier==6 )
alist_shape=zeros(alist_shape);alist_shape(:)=alist(1:numel(alist_shape));alist=alist_shape;
blist_shape=zeros(blist_shape);blist_shape(:)=blist(1:numel(blist_shape));blist=blist_shape;
elist_shape=zeros(elist_shape);elist_shape(:)=elist(1:numel(elist_shape));elist=elist_shape;
iord_shape=zeros(iord_shape);iord_shape(:)=iord(1:numel(iord_shape));iord=iord_shape;
rlist_shape=zeros(rlist_shape);rlist_shape(:)=rlist(1:numel(rlist_shape));rlist=rlist_shape;
return;
end;
%
%
%           FIRST APPROXIMATION TO THE INTEGRAL
%           -----------------------------------
%
%           DETERMINE THE INTERVAL TO BE MAPPED ONTO (0,1).
%           IF INF = 2 THE INTEGRAL IS COMPUTED AS I = I1+I2, WHERE
%           I1 = INTEGRAL OF F OVER (-INFINITY,0),
%           I2 = INTEGRAL OF F OVER (0,+INFINITY).
%
boun = bound;
if( inf==2 )
boun = 0.0e+00;
end;
[f,boun,inf,dumvar4,dumvar5,result,abserr,defabs,resabs]=qk15i(f,boun,inf,0.0e+00,0.1e+01,result,abserr,defabs,resabs);
%
%           TEST ON ACCURACY
%
last = 1;
rlist(1) = result;
elist(1) = abserr;
iord(1) = 1;
dres = abs(result);
errbnd = max(epsabs,epsrel.*dres);
if( abserr<=1.0e+02.*epmach.*defabs && abserr>errbnd )
ier = 2;
end;
if( limit==1 )
ier = 1;
end;
if( ier~=0 ||(abserr<=errbnd && abserr~=resabs) ||abserr==0.0e+00 )
neval = fix(30.*last - 15);
if( inf==2 )
neval = fix(2.*neval);
end;
if( ier>2 )
ier = fix(ier - 1);
end;
alist_shape=zeros(alist_shape);alist_shape(:)=alist(1:numel(alist_shape));alist=alist_shape;
blist_shape=zeros(blist_shape);blist_shape(:)=blist(1:numel(blist_shape));blist=blist_shape;
elist_shape=zeros(elist_shape);elist_shape(:)=elist(1:numel(elist_shape));elist=elist_shape;
iord_shape=zeros(iord_shape);iord_shape(:)=iord(1:numel(iord_shape));iord=iord_shape;
rlist_shape=zeros(rlist_shape);rlist_shape(:)=rlist(1:numel(rlist_shape));rlist=rlist_shape;
return;
end;
%
%           INITIALIZATION
%           --------------
%
[uflow ]=r1mach(1);
[oflow ]=r1mach(2);
rlist2(1) = result;
errmax = abserr;
maxerr = 1;
area = result;
errsum = abserr;
abserr = oflow;
nrmax = 1;
nres = 0;
ktmin = 0;
numrl2 = 2;
extrap = false;
noext = false;
ierro = 0;
iroff1 = 0;
iroff2 = 0;
iroff3 = 0;
ksgn = -1;
if( dres>=(0.1e+01-0.5e+02.*epmach).*defabs )
ksgn = 1;
end;
%
%           MAIN DO-LOOP
%           ------------
%
gt(:)=0;
for last = 2 : limit;
%
%           BISECT THE SUBINTERVAL WITH NRMAX-TH LARGEST
%           ERROR ESTIMATE.
%
a1 = alist(maxerr);
b1 = 0.5e+00.*(alist(maxerr)+blist(maxerr));
a2 = b1;
b2 = blist(maxerr);
erlast = errmax;
[f,boun,inf,a1,b1,area1,error1,resabs,defab1]=qk15i(f,boun,inf,a1,b1,area1,error1,resabs,defab1);
[f,boun,inf,a2,b2,area2,error2,resabs,defab2]=qk15i(f,boun,inf,a2,b2,area2,error2,resabs,defab2);
%
%           IMPROVE PREVIOUS APPROXIMATIONS TO INTEGRAL
%           AND ERROR AND TEST FOR ACCURACY.
%
area12 = area1 + area2;
erro12 = error1 + error2;
errsum = errsum + erro12 - errmax;
area = area + area12 - rlist(maxerr);
if( defab1~=error1 && defab2~=error2 )
if( abs(rlist(maxerr)-area12)<=0.1e-04.*abs(area12) &&erro12>=0.99e+00.*errmax )
if( extrap )
iroff2 = fix(iroff2 + 1);
end;
if( ~extrap )
iroff1 = fix(iroff1 + 1);
end;
end;
if( last>10 && erro12>errmax )
iroff3 = fix(iroff3 + 1);
end;
end;
rlist(maxerr) = area1;
rlist(last) = area2;
errbnd = max(epsabs,epsrel.*abs(area));
%
%           TEST FOR ROUNDOFF ERROR AND EVENTUALLY
%           SET ERROR FLAG.
%
if( iroff1+iroff2>=10 || iroff3>=20 )
ier = 2;
end;
if( iroff2>=5 )
ierro = 3;
end;
%
%           SET ERROR FLAG IN THE CASE THAT THE NUMBER OF
%           SUBINTERVALS EQUALS LIMIT.
%
if( last==limit )
ier = 1;
end;
%
%           SET ERROR FLAG IN THE CASE OF BAD INTEGRAND BEHAVIOUR
%           AT SOME POINTS OF THE INTEGRATION RANGE.
%
if( max(abs(a1),abs(b2))<=(0.1e+01+0.1e+03.*epmach).*(abs(a2)+0.1e+04.*uflow) )
ier = 4;
end;
%
%           APPEND THE NEWLY-CREATED INTERVALS TO THE LIST.
%
if( error2>error1 )
alist(maxerr) = a2;
alist(last) = a1;
blist(last) = b1;
rlist(maxerr) = area2;
rlist(last) = area1;
elist(maxerr) = error2;
elist(last) = error1;
else;
alist(last) = a2;
blist(maxerr) = b1;
blist(last) = b2;
elist(maxerr) = error1;
elist(last) = error2;
end;
%
%           CALL SUBROUTINE QPSRT TO MAINTAIN THE DESCENDING ORDERING
%           IN THE LIST OF ERROR ESTIMATES AND SELECT THE
%           SUBINTERVAL WITH NRMAX-TH LARGEST ERROR ESTIMATE (TO BE
%           BISECTED NEXT).
%
[limit,last,maxerr,errmax,elist,iord,nrmax]=qpsrt(limit,last,maxerr,errmax,elist,iord,nrmax);
if( errsum<=errbnd )
gt(2)=1;
break;
end;
if( ier~=0 )
break;
end;
if( last==2 )
small = 0.375e+00;
erlarg = errsum;
ertest = errbnd;
rlist2(2) = area;
elseif( ~(noext) ) ;
erlarg = erlarg - erlast;
if( abs(b1-a1)>small )
erlarg = erlarg + erro12;
end;
if( ~(extrap) )
%
%           TEST WHETHER THE INTERVAL TO BE BISECTED NEXT IS THE
%           SMALLEST INTERVAL.
%
if( abs(blist(maxerr)-alist(maxerr))>small )
continue;
end;
extrap = true;
nrmax = 2;
end;
if( ierro~=3 && erlarg>ertest )
%
%           THE SMALLEST INTERVAL HAS THE LARGEST ERROR.
%           BEFORE BISECTING DECREASE THE SUM OF THE ERRORS
%           OVER THE LARGER INTERVALS (ERLARG) AND PERFORM
%           EXTRAPOLATION.
%
id = fix(nrmax);
jupbnd = fix(last);
if( last>(2+fix(limit./2)) )
jupbnd = fix(limit + 3 - last);
end;
for k = id : jupbnd;
maxerr = fix(iord(nrmax));
errmax = elist(maxerr);
if( abs(blist(maxerr)-alist(maxerr))>small )
gt(1)=1;
break;
end;
nrmax = fix(nrmax + 1);
end;
if(gt(1)==1)
gt(1)=0;
continue;
end;
end;
%
%           PERFORM EXTRAPOLATION.
%
numrl2 = fix(numrl2 + 1);
rlist2(numrl2) = area;
[numrl2,rlist2,reseps,abseps,res3la,nres]=qelg(numrl2,rlist2,reseps,abseps,res3la,nres);
ktmin = fix(ktmin + 1);
if( ktmin>5 && abserr<0.1e-02.*errsum )
ier = 5;
end;
if( abseps<abserr )
ktmin = 0;
abserr = abseps;
result = reseps;
correc = erlarg;
ertest = max(epsabs,epsrel.*abs(reseps));
if( abserr<=ertest )
break;
end;
end;
%
%            PREPARE BISECTION OF THE SMALLEST INTERVAL.
%
if( numrl2==1 )
noext = true;
end;
if( ier==5 )
break;
end;
maxerr = fix(iord(1));
errmax = elist(maxerr);
nrmax = 1;
extrap = false;
small = small.*0.5e+00;
erlarg = errsum;
end;
end;
%
%           SET FINAL RESULT AND ERROR ESTIMATE.
%           ------------------------------------
%
if(gt(2)==0)
gt(:)=0;
while (1);
if( abserr~=oflow )
if((ier+ierro)~=0 )
if( ierro==3 )
abserr = abserr + correc;
end;
if( ier==0 )
ier = 3;
end;
if( result==0.0e+00 || area==0.0e+00 )
if( abserr>errsum )
break;
end;
if( area==0.0e+00 )
gt(3)=1;
break;
end;
elseif( abserr./abs(result)>errsum./abs(area) ) ;
break;
end;
end;
%
%           TEST ON DIVERGENCE
%
if( ksgn~=(-1) || max(abs(result),abs(area))>defabs.*0.1e-01 )
if( 0.1e-01>(result./area) ||(result./area)>0.1e+03 ||errsum>abs(area) )
ier = 6;
end;
end;
gt(3)=1;
break;
end;
break;
end;
%
%           COMPUTE GLOBAL INTEGRAL SUM.
%
end;
if(gt(3)==0)
result = 0.0e+00;
for k = 1 : last;
result = result + rlist(k);
end; k = fix(last+1);
abserr = errsum;
end;
neval = fix(30.*last - 15);
if( inf==2 )
neval = fix(2.*neval);
end;
if( ier>2 )
ier = fix(ier - 1);
end;
alist_shape=zeros(alist_shape);alist_shape(:)=alist(1:numel(alist_shape));alist=alist_shape;
blist_shape=zeros(blist_shape);blist_shape(:)=blist(1:numel(blist_shape));blist=blist_shape;
elist_shape=zeros(elist_shape);elist_shape(:)=elist(1:numel(elist_shape));elist=elist_shape;
iord_shape=zeros(iord_shape);iord_shape(:)=iord(1:numel(iord_shape));iord=iord_shape;
rlist_shape=zeros(rlist_shape);rlist_shape(:)=rlist(1:numel(rlist_shape));rlist=rlist_shape;
end %subroutine qagie
%DECK QAGI

Contact us at files@mathworks.com