数学算法
源代码在线查看: bs.txt
Function BS(N:integer; A:real):real;
label 5,6,15;
var
B:array[1..20] of real;
DEL,R,EPS,S,AK,A2,DA,AJP,AJM,Q1,Q2,OMEG:real;
M:integer;
begin
If A = 0 Then
begin
If N / 2 = N / 2 Then
begin
B[N]:=0;
GoTo 15;
end;
B[N]:=2 / N;
GoTo 15;
end;
If Abs(A) < 8 Then
begin
DEL:=0.1e-7;
If N / 2 N / 2 Then
begin
R:=2 / N;
EPS:=R * DEL;
S:=R;
AK:=0;
A2:=A * A;
5: AK:=AK + 2;
R:=R * A2 * (N + AK - 2) / (AK * (AK - 1) * (N + AK));
S:=S + R;
If R > EPS Then GoTo 5;
B[N]:=S + R;
GoTo 15;
end;
R:=2 * A / (N + 1);
OMEG:=Abs(R * DEL);
S:=R;
AK:=1;
A2:=A * A;
6: AK:=AK + 2;
R:=R * A2 * (N + AK - 2) / (AK * (AK - 1) * (N + AK));
S:=S + R;
If Abs(R) > OMEG Then GoTo 6;
B[N]:=-(S + R);
GoTo 15;
end;
DA:=1 / A;
AJP:=DA * Exp(A);
AJM:=(DA * DA) / AJP;
B[1]:=AJP - AJM;
If N = 1 Then GoTo 15;
Q1:=-1;
Q2:=1;
For M:= 2 To N do
begin
B[M]:=Q1 * AJP - AJM + Q2 * DA * B[M - 1];
Q1:=-Q1;
Q2:=Q2 + 1;
end;
15: BS:=B[N];
end;