Code covered by the BSD License  

Highlights from
slatec

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

[r9ln2rresult,x]=r9ln2r(x);
function [r9ln2rresult,x]=r9ln2r(x);
r9ln2rresult=[];
persistent eps first firstCall ln21cs ln22cs ntln21 ntln22 r9ln2r sqeps txbig txmax xbig xmax xmin ; if isempty(firstCall),firstCall=1;end; 

if isempty(eps), eps=0; end;
if isempty(r9ln2rresult), r9ln2rresult=0; end;
if isempty(sqeps), sqeps=0; end;
if isempty(txbig), txbig=0; end;
if isempty(txmax), txmax=0; end;
if isempty(xbig), xbig=0; end;
if isempty(xmax), xmax=0; end;
if isempty(xmin), xmin=0; end;
if isempty(ntln21), ntln21=0; end;
if isempty(ntln22), ntln22=0; end;
%***BEGIN PROLOGUE  R9LN2R
%***SUBSIDIARY
%***PURPOSE  Evaluate LOG(1+X) from second order relative accuracy so
%            that LOG(1+X) = X - X**2/2 + X**3*R9LN2R(X).
%***LIBRARY   SLATEC (FNLIB)
%***CATEGORY  C4B
%***TYPE      SINGLE PRECISION (R9LN2R-S, D9LN2R-D, C9LN2R-C)
%***KEYWORDS  ELEMENTARY FUNCTIONS, FNLIB, LOGARITHM, SECOND ORDER
%***AUTHOR  Fullerton, W., (LANL)
%***DESCRIPTION
%
% Evaluate  LOG(1+X)  from 2-nd order with relative error accuracy so
% that    LOG(1+X) = X - X**2/2 + X**3*R9LN2R(X)
%
% Series for LN21       on the interval -6.25000D-01 to  0.
%                                        with weighted error   2.49E-17
%                                         log weighted error  16.60
%                               significant figures required  15.87
%                                    decimal places required  17.31
%
% Series for LN22       on the interval  0.          to  8.12500D-01
%                                        with weighted error   1.42E-17
%                                         log weighted error  16.85
%                               significant figures required  15.95
%                                    decimal places required  17.50
%
%***REFERENCES  (NONE)
%***ROUTINES CALLED  CSEVL, INITS, R1MACH, XERMSG
%***REVISION HISTORY  (YYMMDD)
%   780401  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  R9LN2R
if isempty(ln21cs), ln21cs=zeros(1,26); end;
if isempty(ln22cs), ln22cs=zeros(1,20); end;
if isempty(first), first=false; end;
if firstCall,   ln21cs(1)=[.18111962513478810e0];  end;
if firstCall,   ln21cs(2)=[-.15627123192872463e0];  end;
if firstCall,   ln21cs(3)=[.028676305361557275e0];  end;
if firstCall,   ln21cs(4)=[-.005558699655948139e0];  end;
if firstCall,   ln21cs(5)=[.001117897665229983e0];  end;
if firstCall,   ln21cs(6)=[-.000230805089823279e0];  end;
if firstCall,   ln21cs(7)=[.000048598853341100e0];  end;
if firstCall,   ln21cs(8)=[-.000010390127388903e0];  end;
if firstCall,   ln21cs(9)=[.000002248456370739e0];  end;
if firstCall,   ln21cs(10)=[-.000000491405927392e0];  end;
if firstCall,   ln21cs(11)=[.000000108282565070e0];  end;
if firstCall,   ln21cs(12)=[-.000000024025872763e0];  end;
if firstCall,   ln21cs(13)=[.000000005362460047e0];  end;
if firstCall,   ln21cs(14)=[-.000000001202995136e0];  end;
if firstCall,   ln21cs(15)=[.000000000271078892e0];  end;
if firstCall,   ln21cs(16)=[-.000000000061323562e0];  end;
if firstCall,   ln21cs(17)=[.000000000013920858e0];  end;
if firstCall,   ln21cs(18)=[-.000000000003169930e0];  end;
if firstCall,   ln21cs(19)=[.000000000000723837e0];  end;
if firstCall,   ln21cs(20)=[-.000000000000165700e0];  end;
if firstCall,   ln21cs(21)=[.000000000000038018e0];  end;
if firstCall,   ln21cs(22)=[-.000000000000008741e0];  end;
if firstCall,   ln21cs(23)=[.000000000000002013e0];  end;
if firstCall,   ln21cs(24)=[-.000000000000000464e0];  end;
if firstCall,   ln21cs(25)=[.000000000000000107e0];  end;
if firstCall,   ln21cs(26)=[-.000000000000000024e0];  end;
if firstCall,   ln22cs(1)=[-.22242532535020461e0];  end;
if firstCall,   ln22cs(2)=[-.061047100108078624e0];  end;
if firstCall,   ln22cs(3)=[.007427235009750394e0];  end;
if firstCall,   ln22cs(4)=[-.000933501826163697e0];  end;
if firstCall,   ln22cs(5)=[.000120049907687260e0];  end;
if firstCall,   ln22cs(6)=[-.000015704722952820e0];  end;
if firstCall,   ln22cs(7)=[.000002081874781051e0];  end;
if firstCall,   ln22cs(8)=[-.000000278919557764e0];  end;
if firstCall,   ln22cs(9)=[.000000037693558237e0];  end;
if firstCall,   ln22cs(10)=[-.000000005130902896e0];  end;
if firstCall,   ln22cs(11)=[.000000000702714117e0];  end;
if firstCall,   ln22cs(12)=[-.000000000096748595e0];  end;
if firstCall,   ln22cs(13)=[.000000000013381046e0];  end;
if firstCall,   ln22cs(14)=[-.000000000001858102e0];  end;
if firstCall,   ln22cs(15)=[.000000000000258929e0];  end;
if firstCall,   ln22cs(16)=[-.000000000000036195e0];  end;
if firstCall,   ln22cs(17)=[.000000000000005074e0];  end;
if firstCall,   ln22cs(18)=[-.000000000000000713e0];  end;
if firstCall,   ln22cs(19)=[.000000000000000100e0];  end;
if firstCall,   ln22cs(20)=[-.000000000000000014e0];  end;
if firstCall,   first=[true];  end;
firstCall=0;
%***FIRST EXECUTABLE STATEMENT  R9LN2R
if( first )
[eps ]=r1mach(3);
[ntln21 ,ln21cs]=inits(ln21cs,26,0.1.*eps);
[ntln22 ,ln22cs]=inits(ln22cs,20,0.1.*eps);
%
xmin = -1.0 + sqrt(r1mach(4));
sqeps = sqrt(eps);
txmax = 6.0./sqeps;
xmax = txmax -(eps.*txmax.^2-2.0.*log(txmax))./(2.0.*eps.*txmax);
txbig = 4.0./sqrt(sqeps);
xbig = txbig -(sqeps.*txbig.^2-2.0.*log(txbig))./(2..*sqeps.*txbig);
end;
first = false;
%
if( x<(-0.625) || x>0.8125 )
%
if( x<xmin )
xermsg('SLATEC','R9LN2R','ANSWER LT HALF PRECISION BECAUSE X IS TOO NEAR -1',1,1);
end;
if( x>xmax )
xermsg('SLATEC','R9LN2R','NO PRECISION IN ANSWER BECAUSE X IS TOO BIG',3,2);
end;
if( x>xbig )
xermsg('SLATEC','R9LN2R','ANSWER LT HALF PRECISION BECAUSE X IS TOO BIG',2,1);
end;
%
r9ln2rresult =(log(1.0+x)-x.*(1.0-0.5.*x))./x.^3;
else;
%
if( x<0.0 )
r9ln2rresult = 0.375 + csevl(16..*x./5.+1.0,ln21cs,ntln21);
end;
if( x>=0.0 )
r9ln2rresult = 0.375 + csevl(32..*x./13.-1.0,ln22cs,ntln22);
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 R9PAK

Contact us at files@mathworks.com