Code covered by the BSD License  

Highlights from
slatec

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

[r9lgmcresult,x]=r9lgmc(x);
function [r9lgmcresult,x]=r9lgmc(x);
r9lgmcresult=[];
persistent algmcs first firstCall nalgm r9lgmc xbig xmax ; if isempty(firstCall),firstCall=1;end; 

if isempty(algmcs), algmcs=zeros(1,6); end;
if isempty(r9lgmcresult), r9lgmcresult=0; end;
if isempty(xbig), xbig=0; end;
if isempty(xmax), xmax=0; end;
if isempty(nalgm), nalgm=0; end;
%***BEGIN PROLOGUE  R9LGMC
%***SUBSIDIARY
%***PURPOSE  Compute the log Gamma correction factor so that
%            LOG(GAMMA(X)) = LOG(SQRT(2*PI)) + (X-.5)*LOG(X) - X
%            + R9LGMC(X).
%***LIBRARY   SLATEC (FNLIB)
%***CATEGORY  C7E
%***TYPE      SINGLE PRECISION (R9LGMC-S, D9LGMC-D, C9LGMC-C)
%***KEYWORDS  COMPLETE GAMMA FUNCTION, CORRECTION TERM, FNLIB,
%             LOG GAMMA, LOGARITHM, SPECIAL FUNCTIONS
%***AUTHOR  Fullerton, W., (LANL)
%***DESCRIPTION
%
% Compute the log gamma correction factor for X .GE. 10.0 so that
%  LOG (GAMMA(X)) = LOG(SQRT(2*PI)) + (X-.5)*LOG(X) - X + R9LGMC(X)
%
% Series for ALGM       on the interval  0.          to  1.00000D-02
%                                        with weighted error   3.40E-16
%                                         log weighted error  15.47
%                               significant figures required  14.39
%                                    decimal places required  15.86
%
%***REFERENCES  (NONE)
%***ROUTINES CALLED  CSEVL, INITS, R1MACH, XERMSG
%***REVISION HISTORY  (YYMMDD)
%   770801  DATE WRITTEN
%   890531  Changed all specific intrinsics to generic.  (WRB)
%   890531  REVISION DATE from Version 3.2
%   891214  Prologue converted to Version 4.0 format.  (BAB)
%   900315  CALLs to XERROR changed to CALLs to XERMSG.  (THJ)
%   900720  Routine changed from user-callable to subsidiary.  (WRB)
%***end PROLOGUE  R9LGMC
if isempty(first), first=false; end;
if firstCall,   algmcs(1)=[.166638948045186e0];  end;
if firstCall,   algmcs(2)=[-.0000138494817606e0];  end;
if firstCall,   algmcs(3)=[.0000000098108256e0];  end;
if firstCall,   algmcs(4)=[-.0000000000180912e0];  end;
if firstCall,   algmcs(5)=[.0000000000000622e0];  end;
if firstCall,   algmcs(6)=[-.0000000000000003e0];  end;
if firstCall,   first=[true];  end;
firstCall=0;
%***FIRST EXECUTABLE STATEMENT  R9LGMC
if( first )
[nalgm ,algmcs]=inits(algmcs,6,r1mach(3));
xbig = 1.0./sqrt(r1mach(3));
xmax = exp(min(log(r1mach(2)./12.0),-log(12.0.*r1mach(1))));
end;
first = false;
%
if( x<10.0 )
xermsg('SLATEC','R9LGMC','X MUST BE GE 10',1,2);
end;
if( x>=xmax )
%
r9lgmcresult = 0.0;
xermsg('SLATEC','R9LGMC','X SO BIG R9LGMC UNDERFLOWS',2,1);
else;
%
r9lgmcresult = 1.0./(12.0.*x);
if( x<xbig )
r9lgmcresult = csevl(2.0.*(10../x).^2-1.,algmcs,nalgm)./x;
end;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
end;
%
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
end
%DECK R9LN2R

Contact us