Code covered by the BSD License  

Highlights from
slatec

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

[erfcresult,x]=erfc(x);
function [erfcresult,x]=erfc(x);
erfcresult=[];
persistent erc2cs erfc erfccs erfcs eta first firstCall nterc2 nterf nterfc sqeps sqrtpi txmax xmax xsml y ; if isempty(firstCall),firstCall=1;end; 

if isempty(erc2cs), erc2cs=zeros(1,23); end;
if isempty(erfcresult), erfcresult=0; end;
if isempty(erfccs), erfccs=zeros(1,24); end;
if isempty(erfcs), erfcs=zeros(1,13); end;
if isempty(eta), eta=0; end;
if isempty(sqeps), sqeps=0; end;
if isempty(sqrtpi), sqrtpi=0; end;
if isempty(txmax), txmax=0; end;
if isempty(xmax), xmax=0; end;
if isempty(xsml), xsml=0; end;
if isempty(y), y=0; end;
if isempty(nterc2), nterc2=0; end;
if isempty(nterf), nterf=0; end;
if isempty(nterfc), nterfc=0; end;
%***BEGIN PROLOGUE  ERFC
%***PURPOSE  Compute the complementary error function.
%***LIBRARY   SLATEC (FNLIB)
%***CATEGORY  C8A, L5A1E
%***TYPE      SINGLE PRECISION (ERFC-S, DERFC-D)
%***KEYWORDS  COMPLEMENTARY ERROR FUNCTION, ERFC, FNLIB,
%             SPECIAL FUNCTIONS
%***AUTHOR  Fullerton, W., (LANL)
%***DESCRIPTION
%
% ERFC(X) calculates the single precision complementary error
% function for single precision argument X.
%
% Series for ERF        on the interval  0.          to  1.00000D+00
%                                        with weighted error   7.10E-18
%                                         log weighted error  17.15
%                               significant figures required  16.31
%                                    decimal places required  17.71
%
% Series for ERFC       on the interval  0.          to  2.50000D-01
%                                        with weighted error   4.81E-17
%                                         log weighted error  16.32
%                        approx significant figures required  15.0
%
%
% Series for ERC2       on the interval  2.50000D-01 to  1.00000D+00
%                                        with weighted error   5.22E-17
%                                         log weighted error  16.28
%                        approx significant figures required  15.0
%                                    decimal places required  16.96
%
%***REFERENCES  (NONE)
%***ROUTINES CALLED  CSEVL, INITS, R1MACH, XERMSG
%***REVISION HISTORY  (YYMMDD)
%   770701  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)
%   920618  Removed space from variable names.  (RWC, WRB)
%***end PROLOGUE  ERFC
if isempty(first), first=false; end;
if firstCall,   erfcs(1)=[-.049046121234691808e0];  end;
if firstCall,   erfcs(2)=[-.14226120510371364e0];  end;
if firstCall,   erfcs(3)=[.010035582187599796e0];  end;
if firstCall,   erfcs(4)=[-.000576876469976748e0];  end;
if firstCall,   erfcs(5)=[.000027419931252196e0];  end;
if firstCall,   erfcs(6)=[-.000001104317550734e0];  end;
if firstCall,   erfcs(7)=[.000000038488755420e0];  end;
if firstCall,   erfcs(8)=[-.000000001180858253e0];  end;
if firstCall,   erfcs(9)=[.000000000032334215e0];  end;
if firstCall,   erfcs(10)=[-.000000000000799101e0];  end;
if firstCall,   erfcs(11)=[.000000000000017990e0];  end;
if firstCall,   erfcs(12)=[-.000000000000000371e0];  end;
if firstCall,   erfcs(13)=[.000000000000000007e0];  end;
if firstCall,   erc2cs(1)=[-.069601346602309501e0];  end;
if firstCall,   erc2cs(2)=[-.041101339362620893e0];  end;
if firstCall,   erc2cs(3)=[.003914495866689626e0];  end;
if firstCall,   erc2cs(4)=[-.000490639565054897e0];  end;
if firstCall,   erc2cs(5)=[.000071574790013770e0];  end;
if firstCall,   erc2cs(6)=[-.000011530716341312e0];  end;
if firstCall,   erc2cs(7)=[.000001994670590201e0];  end;
if firstCall,   erc2cs(8)=[-.000000364266647159e0];  end;
if firstCall,   erc2cs(9)=[.000000069443726100e0];  end;
if firstCall,   erc2cs(10)=[-.000000013712209021e0];  end;
if firstCall,   erc2cs(11)=[.000000002788389661e0];  end;
if firstCall,   erc2cs(12)=[-.000000000581416472e0];  end;
if firstCall,   erc2cs(13)=[.000000000123892049e0];  end;
if firstCall,   erc2cs(14)=[-.000000000026906391e0];  end;
if firstCall,   erc2cs(15)=[.000000000005942614e0];  end;
if firstCall,   erc2cs(16)=[-.000000000001332386e0];  end;
if firstCall,   erc2cs(17)=[.000000000000302804e0];  end;
if firstCall,   erc2cs(18)=[-.000000000000069666e0];  end;
if firstCall,   erc2cs(19)=[.000000000000016208e0];  end;
if firstCall,   erc2cs(20)=[-.000000000000003809e0];  end;
if firstCall,   erc2cs(21)=[.000000000000000904e0];  end;
if firstCall,   erc2cs(22)=[-.000000000000000216e0];  end;
if firstCall,   erc2cs(23)=[.000000000000000052e0];  end;
if firstCall,   erfccs(1)=[0.0715179310202925e0];  end;
if firstCall,   erfccs(2)=[-.026532434337606719e0];  end;
if firstCall,   erfccs(3)=[.001711153977920853e0];  end;
if firstCall,   erfccs(4)=[-.000163751663458512e0];  end;
if firstCall,   erfccs(5)=[.000019871293500549e0];  end;
if firstCall,   erfccs(6)=[-.000002843712412769e0];  end;
if firstCall,   erfccs(7)=[.000000460616130901e0];  end;
if firstCall,   erfccs(8)=[-.000000082277530261e0];  end;
if firstCall,   erfccs(9)=[.000000015921418724e0];  end;
if firstCall,   erfccs(10)=[-.000000003295071356e0];  end;
if firstCall,   erfccs(11)=[.000000000722343973e0];  end;
if firstCall,   erfccs(12)=[-.000000000166485584e0];  end;
if firstCall,   erfccs(13)=[.000000000040103931e0];  end;
if firstCall,   erfccs(14)=[-.000000000010048164e0];  end;
if firstCall,   erfccs(15)=[.000000000002608272e0];  end;
if firstCall,   erfccs(16)=[-.000000000000699105e0];  end;
if firstCall,   erfccs(17)=[.000000000000192946e0];  end;
if firstCall,   erfccs(18)=[-.000000000000054704e0];  end;
if firstCall,   erfccs(19)=[.000000000000015901e0];  end;
if firstCall,   erfccs(20)=[-.000000000000004729e0];  end;
if firstCall,   erfccs(21)=[.000000000000001432e0];  end;
if firstCall,   erfccs(22)=[-.000000000000000439e0];  end;
if firstCall,   erfccs(23)=[.000000000000000138e0];  end;
if firstCall,   erfccs(24)=[-.000000000000000048e0];  end;
if firstCall,   sqrtpi=[1.7724538509055160e0];  end;
if firstCall,   first=[true];  end;
firstCall=0;
%***FIRST EXECUTABLE STATEMENT  ERFC
if( first )
eta = 0.1.*r1mach(3);
[nterf ,erfcs,dumvar3,eta]=inits(erfcs,13,eta);
[nterfc ,erfccs,dumvar3,eta]=inits(erfccs,24,eta);
[nterc2 ,erc2cs,dumvar3,eta]=inits(erc2cs,23,eta);
%
xsml = -sqrt(-log(sqrtpi.*r1mach(3)));
txmax = sqrt(-log(sqrtpi.*r1mach(1)));
xmax = txmax - 0.5.*log(txmax)./txmax - 0.01;
sqeps = sqrt(2.0.*r1mach(3));
end;
first = false;
%
if( x<=xsml )
%
% ERFC(X) = 1.0 - ERF(X) FOR X .LT. XSML
%
erfcresult = 2.;
csnil=dbstack(1); csnil=csnil(1).name(1)~='@';
if csnil&&~isempty(inputname(1)), assignin('caller','FUntemp',x); evalin('caller',[inputname(1),'=FUntemp;']); end
return;
%
elseif( x>xmax ) ;
%
xermsg('SLATEC','ERFC','X SO BIG ERFC UNDERFLOWS',1,1);
erfcresult = 0.;
else;
y = abs(x);
if( y>1.0 )
%
% ERFC(X) = 1.0 - ERF(X) FOR 1. .LT. ABS(X) .LE. XMAX
%
y = y.*y;
if( y<=4. )
erfcresult = exp(-y)./abs(x).*(0.5+csevl((8../y-5.)./3.,erc2cs,nterc2));
end;
if( y>4. )
erfcresult = exp(-y)./abs(x).*(0.5+csevl(8../y-1.,erfccs,nterfc));
end;
if( x<0. )
erfcresult = 2.0 - erfcresult;
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;
else;
%
% ERFC(X) = 1.0 - ERF(X) FOR -1. .LE. X .LE. 1.
%
if( y<sqeps )
erfcresult = 1.0 - 2.0.*x./sqrtpi;
end;
if( y>=sqeps )
erfcresult = 1.0 - x.*(1.0+csevl(2..*x.*x-1.,erfcs,nterf));
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;
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 ERF

Contact us at files@mathworks.com