Category : Pascal Source Code
Archive   : PAS-SCI.ZIP
Filename : ERFD3.PAS

 
Output of file : ERFD3.PAS contained in archive : PAS-SCI.ZIP
program erfd3; { -> 330 }
{ evaluation of the gaussian error function }

var x,er,ec : real;
done : boolean;

function erf(x: real): real;
{ infinite series expansion of the Gaussian error function }

const sqrtpi = 1.7724538;
tol = 1.0E-4;

var x2,sum,sum1,term: real;
i : integer;

begin
x2:=x*x;
sum:=x;
term:=x;
i:=0;
repeat
i:=i+1;
sum1:=sum;
term:=2.0*term*x2/(1.0+2.0*i);
sum:=term+sum1
until term erf:=2.0*sum*exp(-x2)/sqrtpi
end; { erf }

function erfc(x: real): real;
{ complement of error function }
const sqrtpi = 1.7724538;
terms = 12;

var x2,u,v,sum : real;
i : integer;
begin
x2:=x*x;
v:=1.0/(2.0*x2);
u:=1.0+v*(terms+1.0);
for i:=terms downto 1 do
begin
sum:=1.0+i*v/u;
u:=sum
end;
erfc:=exp(-x2)/(x*sum*sqrtpi)
end; { ercf }

begin { main }
ClrScr;
done:=false;
writeln;
repeat
write('Arg? ');
readln(x);
if x<0.0 then done:=true

else
begin
if x=0.0 then
begin
er:=0.0;
ec:=1.0
end
else
begin
if x<1.5 then
begin
er:=erf(x);
ec:=1.0-er
end
else
begin
ec:=erfc(x);
er:=1.0-ec
end { if }
end;
writeln('X= ',x:8:4,' Erf= ',er:12:8,', Erfc= ',ec:12)
end { if }
until done
end.


  3 Responses to “Category : Pascal Source Code
Archive   : PAS-SCI.ZIP
Filename : ERFD3.PAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/