Code covered by the BSD License  

Highlights from
GaussHermite

GaussHermite

by

 

26 Aug 2008 (Updated )

Gauss-Hermite quadrature using tabulated abscissas and weights

GaussHermite(func, npt, varargin)
function fn_val = GaussHermite(func, npt, varargin) 
%
%       HERMITE INTEGRATION, I.E. EVALUATION OF THE INTEGRAL OF
%       exp(-x**2)*f(x) FROM -INFINITY TO +INFINITY
%
%       NPT     = INPUT, NO. OF POINTS AT WHICH f(x) IS TO BE EVALUATED.
%                 NPT MUST BE ONE OF 2, 4, 6, 8, 10, 12, 16, 20.
%       FUNC    = INPUT, NAME OF THE USER'S FUNCTION TO SUPPLY VALUES
%                 OF F(X).
%       varargin contains any extra parameters for FUNC
%
% Based on hermite.f90 from Alan Miller's Fortran site:
% http://users.bigpond.net.au/amiller/
% Converted from Fortran90 using f2matlab + manual editing
% Code rewritten with MATLAB constructs
% S Bocquet 28 July 2008 Tested with MATLAB Version 7.6.0.324 (R2008a)
%************************************************************************

persistent npts ipos wt xpt 

%     Local variables

if isempty(xpt), xpt(1:39) =[ 0.707106781186548,0.524647623275290, 1.650680123885785,0.436077411927617, 1.335849074013697, 2.350604973674492,0.381186990207322, 1.157193712446780, 1.981656756695843,2.930637420257244,0.342901327223705, 1.036610829789514, 1.756683649299882,2.532731674232790, 3.436159118837738,0.314240376254359, 0.947788391240164, 1.597682635152605,2.279507080501060, 3.020637025120890, 3.889724897869782,0.27348104613815,  0.82295144914466, 1.38025853919888,1.95178799091625,  2.54620215784748, 3.17699916197996,3.86944790486012,  4.68873893930582,0.2453407083009,   0.7374737285454, 1.2340762153953,1.7385377121166,   2.2549740020893, 2.7888060584281,3.3478545673832,   3.9447640401156, 4.6036824495507,5.3874808900112 ]; end;
if isempty(wt), wt(1:39) =[ 8.862269254528d-1,8.049140900055d-1, 8.131283544725d-2,7.246295952244d-1, 1.570673203229d-1, 4.530009905509d-3,6.611470125582d-1, 2.078023258149d-1, 1.707798300741d-2,1.996040722114d-4,6.108626337353d-1, 2.401386110823d-1, 3.387439445548d-2,1.343645746781d-3, 7.640432855233d-6,5.701352362625d-1, 2.604923102642d-1, 5.160798561588d-2,3.905390584629d-3, 8.573687043588d-5, 2.658551684356d-7,5.079294790166d-1, 2.806474585285d-1, 8.381004139899d-2,1.288031153551d-2, 9.322840086242d-4, 2.711860092538d-5,2.320980844865d-7, 2.654807474011d-10,4.622436696006d-1, 2.866755053628d-1, 1.090172060200d-1,2.481052088746d-2, 3.243773342238d-3, 2.283386360163d-4,7.802556478532d-6, 1.086069370769d-7, 4.399340992273d-10,2.229393645534d-13 ]; end;
if isempty(npts), npts(1:8) = int8([ 2, 4, 6, 8, 10, 12, 16, 20 ]); end;
if isempty(ipos), ipos(1:9) = int8([ 1, 2, 4, 7, 11, 16, 22, 30, 40 ]); end;

%       CHECK FOR PERMISSIBLE VALUE OF NPT.

j = find(npt==npts);
if isempty(j)
  error('GaussHermite:InvalidNpt','Invalid number of points: npt must be 2,4,6,8,10,12,16 or 20')
end

%       EVALUATE SUM OF WT(I) * FUNC(X(I))

i = ipos(j):ipos(j+1)-1;
fn_val = dot(wt(i),(func(xpt(i),varargin{:}) + func(-xpt(i),varargin{:})));

return

end %function GaussHermite

Contact us