Code covered by the BSD License  

Highlights from
slatec

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

[psixnresult,n]=psixn(n);
function [psixnresult,n]=psixn(n);
psixnresult=[];
persistent ax b c firstCall fn k psixn rfn2 s trm wdtol ; if isempty(firstCall),firstCall=1;end; 

if isempty(psixnresult), psixnresult=0; end;
%***BEGIN PROLOGUE  PSIXN
%***SUBSIDIARY
%***PURPOSE  Subsidiary to EXINT
%***LIBRARY   SLATEC
%***TYPE      SINGLE PRECISION (PSIXN-S, DPSIXN-D)
%***AUTHOR  Amos, D. E., (SNLA)
%***DESCRIPTION
%
%     This subroutine returns values of PSI(X)=derivative of log
%     GAMMA(X), X .GT. 0.0 at integer arguments. A table look-up is
%     performed for N .LE. 100, and the asymptotic expansion is
%     evaluated for N .GT. 100.
%
%***SEE ALSO  EXINT
%***ROUTINES CALLED  R1MACH
%***REVISION HISTORY  (YYMMDD)
%   800501  DATE WRITTEN
%   890531  Changed all specific intrinsics to generic.  (WRB)
%   891214  Prologue converted to Version 4.0 format.  (BAB)
%   900328  Added TYPE section.  (WRB)
%   910722  Updated AUTHOR section.  (ALS)
%***end PROLOGUE  PSIXN
%
if isempty(k), k=0; end;
if isempty(ax), ax=0; end;
if isempty(b), b=zeros(1,6); end;
if isempty(c), c=zeros(1,100); end;
if isempty(fn), fn=0; end;
if isempty(rfn2), rfn2=0; end;
if isempty(trm), trm=0; end;
if isempty(s), s=0; end;
if isempty(wdtol), wdtol=0; end;
%-----------------------------------------------------------------------
%             PSIXN(N), N = 1,100
%-----------------------------------------------------------------------
if firstCall,   c(1) =[-5.77215664901532861e-01];  end;
if firstCall,  c(2) =[4.22784335098467139e-01];  end;
if firstCall,  c(3) =[9.22784335098467139e-01];  end;
if firstCall,  c(4) =[1.25611766843180047e+00];  end;
if firstCall,  c(5) =[1.50611766843180047e+00];  end;
if firstCall,  c(6) =[1.70611766843180047e+00];  end;
if firstCall,  c(7) =[1.87278433509846714e+00];  end;
if firstCall,  c(8) =[2.01564147795561000e+00];  end;
if firstCall, c(9) =[2.14064147795561000e+00];  end;
if firstCall,  c(10) =[2.25175258906672111e+00];  end;
if firstCall,  c(11) =[2.35175258906672111e+00];  end;
if firstCall,  c(12) =[2.44266167997581202e+00];  end;
if firstCall,  c(13) =[2.52599501330914535e+00];  end;
if firstCall,  c(14) =[2.60291809023222227e+00];  end;
if firstCall,  c(15) =[2.67434666166079370e+00];  end;
if firstCall, c(16) =[2.74101332832746037e+00];  end;
if firstCall,  c(17) =[2.80351332832746037e+00];  end;
if firstCall,  c(18) =[2.86233685773922507e+00];  end;
if firstCall,  c(19) =[2.91789241329478063e+00];  end;
if firstCall,  c(20) =[2.97052399224214905e+00];  end;
if firstCall,  c(21) =[3.02052399224214905e+00];  end;
if firstCall,  c(22) =[3.06814303986119667e+00];  end;
if firstCall, c(23) =[3.11359758531574212e+00];  end;
if firstCall,  c(24)=[3.15707584618530734e+00];  end;
if firstCall,   c(25) =[3.19874251285197401e+00];  end;
if firstCall,  c(26) =[3.23874251285197401e+00];  end;
if firstCall,  c(27) =[3.27720405131351247e+00];  end;
if firstCall,  c(28) =[3.31424108835054951e+00];  end;
if firstCall,  c(29) =[3.34995537406483522e+00];  end;
if firstCall,  c(30) =[3.38443813268552488e+00];  end;
if firstCall,  c(31) =[3.41777146601885821e+00];  end;
if firstCall, c(32) =[3.45002953053498724e+00];  end;
if firstCall,  c(33) =[3.48127953053498724e+00];  end;
if firstCall,  c(34) =[3.51158256083801755e+00];  end;
if firstCall,  c(35) =[3.54099432554389990e+00];  end;
if firstCall,  c(36) =[3.56956575411532847e+00];  end;
if firstCall,  c(37) =[3.59734353189310625e+00];  end;
if firstCall,  c(38) =[3.62437055892013327e+00];  end;
if firstCall, c(39) =[3.65068634839381748e+00];  end;
if firstCall,  c(40) =[3.67632737403484313e+00];  end;
if firstCall,  c(41) =[3.70132737403484313e+00];  end;
if firstCall,  c(42) =[3.72571761793728215e+00];  end;
if firstCall,  c(43) =[3.74952714174680596e+00];  end;
if firstCall,  c(44) =[3.77278295570029433e+00];  end;
if firstCall,  c(45) =[3.79551022842756706e+00];  end;
if firstCall, c(46) =[3.81773245064978928e+00];  end;
if firstCall,  c(47) =[3.83947158108457189e+00];  end;
if firstCall,  c(48)=[3.86074817682925274e+00];  end;
if firstCall,   c(49) =[3.88158151016258607e+00];  end;
if firstCall,  c(50) =[3.90198967342789220e+00];  end;
if firstCall,  c(51) =[3.92198967342789220e+00];  end;
if firstCall,  c(52) =[3.94159751656514710e+00];  end;
if firstCall,  c(53) =[3.96082828579591633e+00];  end;
if firstCall,  c(54) =[3.97969621032421822e+00];  end;
if firstCall,  c(55) =[3.99821472884273674e+00];  end;
if firstCall, c(56) =[4.01639654702455492e+00];  end;
if firstCall,  c(57) =[4.03425368988169777e+00];  end;
if firstCall,  c(58) =[4.05179754953082058e+00];  end;
if firstCall,  c(59) =[4.06903892884116541e+00];  end;
if firstCall,  c(60) =[4.08598808138353829e+00];  end;
if firstCall,  c(61) =[4.10265474805020496e+00];  end;
if firstCall,  c(62) =[4.11904819067315578e+00];  end;
if firstCall, c(63) =[4.13517722293122029e+00];  end;
if firstCall,  c(64) =[4.15105023880423617e+00];  end;
if firstCall,  c(65) =[4.16667523880423617e+00];  end;
if firstCall,  c(66) =[4.18205985418885155e+00];  end;
if firstCall,  c(67) =[4.19721136934036670e+00];  end;
if firstCall,  c(68) =[4.21213674247469506e+00];  end;
if firstCall,  c(69) =[4.22684262482763624e+00];  end;
if firstCall, c(70) =[4.24133537845082464e+00];  end;
if firstCall,  c(71) =[4.25562109273653893e+00];  end;
if firstCall,  c(72)=[4.26970559977879245e+00];  end;
if firstCall,   c(73) =[4.28359448866768134e+00];  end;
if firstCall,  c(74) =[4.29729311880466764e+00];  end;
if firstCall,  c(75) =[4.31080663231818115e+00];  end;
if firstCall,  c(76) =[4.32413996565151449e+00];  end;
if firstCall,  c(77) =[4.33729786038835659e+00];  end;
if firstCall,  c(78) =[4.35028487337536958e+00];  end;
if firstCall,  c(79) =[4.36310538619588240e+00];  end;
if firstCall, c(80) =[4.37576361404398366e+00];  end;
if firstCall,  c(81) =[4.38826361404398366e+00];  end;
if firstCall,  c(82) =[4.40060929305632934e+00];  end;
if firstCall,  c(83) =[4.41280441500754886e+00];  end;
if firstCall,  c(84) =[4.42485260777863319e+00];  end;
if firstCall,  c(85) =[4.43675736968339510e+00];  end;
if firstCall,  c(86) =[4.44852207556574804e+00];  end;
if firstCall, c(87) =[4.46014998254249223e+00];  end;
if firstCall,  c(88) =[4.47164423541605544e+00];  end;
if firstCall,  c(89) =[4.48300787177969181e+00];  end;
if firstCall,  c(90) =[4.49424382683587158e+00];  end;
if firstCall,  c(91) =[4.50535493794698269e+00];  end;
if firstCall,  c(92) =[4.51634394893599368e+00];  end;
if firstCall,  c(93) =[4.52721351415338499e+00];  end;
if firstCall, c(94) =[4.53796620232542800e+00];  end;
if firstCall,  c(95) =[4.54860450019776842e+00];  end;
if firstCall,  c(96)=[4.55913081598724211e+00];  end;
if firstCall,   c(97) =[4.56954748265390877e+00];  end;
if firstCall,  c(98) =[4.57985676100442424e+00];  end;
if firstCall,  c(99) =[4.59006084263707730e+00];  end;
if firstCall,  c(100)=[4.60016185273808740e+00];  end;
%-----------------------------------------------------------------------
%             COEFFICIENTS OF ASYMPTOTIC EXPANSION
%-----------------------------------------------------------------------
if firstCall,   b(1) =[8.33333333333333333e-02];  end;
if firstCall,  b(2) =[-8.33333333333333333e-03];  end;
if firstCall,  b(3) =[3.96825396825396825e-03];  end;
if firstCall,  b(4) =[-4.16666666666666666e-03];  end;
if firstCall,  b(5) =[7.57575757575757576e-03];  end;
if firstCall, b(6)=[-2.10927960927960928e-02];  end;
firstCall=0;
%
%***FIRST EXECUTABLE STATEMENT  PSIXN
if( n>100 )
wdtol = max(r1mach(4),1.0e-18);
fn = n;
ax = 1.0e0;
s = -0.5e0./fn;
if( abs(s)>wdtol )
rfn2 = 1.0e0./(fn.*fn);
for k = 1 : 6;
ax = ax.*rfn2;
trm = -b(k).*ax;
if( abs(trm)<wdtol )
break;
end;
s = s + trm;
end;
end;
psixnresult = s + log(fn);
else;
psixnresult = c(n);
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',n); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
end;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',n); evalin('caller',[inputname(1),'=FUntemp;']); end
end
%DECK PVALUE

Contact us at files@mathworks.com