Code covered by the BSD License  

Highlights from
slatec

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

[r9atn1result,x]=r9atn1(x);
function [r9atn1result,x]=r9atn1(x);
r9atn1result=[];
persistent atn1cs eps first firstCall ntatn1 r9atn1 xbig xmax xsml y ; if isempty(firstCall),firstCall=1;end; 

if isempty(atn1cs), atn1cs=zeros(1,21); end;
if isempty(eps), eps=0; end;
if isempty(r9atn1result), r9atn1result=0; end;
if isempty(xbig), xbig=0; end;
if isempty(xmax), xmax=0; end;
if isempty(xsml), xsml=0; end;
if isempty(y), y=0; end;
if isempty(ntatn1), ntatn1=0; end;
%***BEGIN PROLOGUE  R9ATN1
%***SUBSIDIARY
%***PURPOSE  Evaluate ATAN(X) from first order relative accuracy so that
%            ATAN(X) = X + X**3*R9ATN1(X).
%***LIBRARY   SLATEC (FNLIB)
%***CATEGORY  C4A
%***TYPE      SINGLE PRECISION (R9ATN1-S, D9ATN1-D)
%***KEYWORDS  ARC TANGENT, ELEMENTARY FUNCTIONS, FIRST ORDER, FNLIB,
%             TRIGONOMETRIC
%***AUTHOR  Fullerton, W., (LANL)
%***DESCRIPTION
%
% Evaluate  ATAN(X)  from first order, that is, evaluate
% (ATAN(X)-X)/X**3  with relative error accuracy so that
%        ATAN(X) = X + X**3*R9ATN1(X).
%
% Series for ATN1       on the interval  0.          to  1.00000D+00
%                                        with weighted error   2.21E-17
%                                         log weighted error  16.66
%                               significant figures required  15.44
%                                    decimal places required  17.32
%
%***REFERENCES  (NONE)
%***ROUTINES CALLED  CSEVL, INITS, R1MACH, XERMSG
%***REVISION HISTORY  (YYMMDD)
%   780401  DATE WRITTEN
%   890206  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  R9ATN1
if isempty(first), first=false; end;
if firstCall,   atn1cs(1)=[-.03283997535355202e0];  end;
if firstCall,   atn1cs(2)=[.05833432343172412e0];  end;
if firstCall,   atn1cs(3)=[-.00740036969671964e0];  end;
if firstCall,   atn1cs(4)=[.00100978419933728e0];  end;
if firstCall,   atn1cs(5)=[-.00014397871635652e0];  end;
if firstCall,   atn1cs(6)=[.00002114512648992e0];  end;
if firstCall,   atn1cs(7)=[-.00000317232107425e0];  end;
if firstCall,   atn1cs(8)=[.00000048366203654e0];  end;
if firstCall,   atn1cs(9)=[-.00000007467746546e0];  end;
if firstCall,   atn1cs(10)=[.00000001164800896e0];  end;
if firstCall,   atn1cs(11)=[-.00000000183208837e0];  end;
if firstCall,   atn1cs(12)=[.00000000029019082e0];  end;
if firstCall,   atn1cs(13)=[-.00000000004623885e0];  end;
if firstCall,   atn1cs(14)=[.00000000000740552e0];  end;
if firstCall,   atn1cs(15)=[-.00000000000119135e0];  end;
if firstCall,   atn1cs(16)=[.00000000000019240e0];  end;
if firstCall,   atn1cs(17)=[-.00000000000003118e0];  end;
if firstCall,   atn1cs(18)=[.00000000000000506e0];  end;
if firstCall,   atn1cs(19)=[-.00000000000000082e0];  end;
if firstCall,   atn1cs(20)=[.00000000000000013e0];  end;
if firstCall,   atn1cs(21)=[-.00000000000000002e0];  end;
if firstCall,   first=[true];  end;
firstCall=0;
%***FIRST EXECUTABLE STATEMENT  R9ATN1
if( first )
[eps ]=r1mach(3);
[ntatn1 ,atn1cs]=inits(atn1cs,21,0.1.*eps);
%
xsml = sqrt(0.1.*eps);
xbig = 1.571./sqrt(eps);
xmax = 1.571./eps;
end;
first = false;
%
y = abs(x);
if( y>1.0 )
%
if( y>xmax )
xermsg('SLATEC','R9ATN1','NO PRECISION IN ANSWER BECAUSE X IS TOO BIG',2,2);
end;
if( y>xbig )
xermsg('SLATEC','R9ATN1','ANSWER LT HALF PRECISION BECAUSE X IS TOO BIG',1,1);
end;
%
r9atn1result =(atan(x)-x)./x.^3;
else;
%
if( y<=xsml )
r9atn1result = -1.0./3.0;
end;
if( y<=xsml )
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;
%
r9atn1result = -0.25 + csevl(2.0.*y.*y-1.,atn1cs,ntatn1);
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 R9CHU

Contact us at files@mathworks.com