Abt. Gauss´sche Fehlerfunktion für selten tabellierte Bereiche
======================================
Vorab der englische Begleittext zum übersetzten Quelltext:
Spoiler anzeigen
The error function erf(x) can be approximated with an asymptotic series.
x -t^2 dt
erf(x) = 2/sqrt(pi) Sum e
0
This function or its complement, erfc(x) = 1 - erf(x), is often involved
in the solutions to heat transfer and ionic diffusion problems. It also
appears in statistics. In many cases, there is need to know the value of
erf(x) for large values of the argument ( x > 3); tables seldom cover
this range adequately.
Peirce gives a convenient asymptotic expansion for positive values of x:
___________1____ 1 x 3_____ 1 x 3 x 5
erf(x) = 1 - ---- + ----------- - --------- + ...
_________2x^2 _(2x^2)^2 __(2x^2)^3
As with most asymptotic series, the above expression eventually diverges.
However, we can again terminate the summation at the smallest term and
use the magnitude of the next term as a measure of the error bound. This
is done in program ASYMERF: The input is X, the returned values are
Y = erf(X), Y1 = erfc(X), the error estimate E and the number of terms
summed, N.
For x <= 3, a rapidly convergent Taylor series approximation can be used:
erf(x) = (2/sqrt(pi)) (x - x^3 / 3 + x^5 / (5 * 2!) - x^7 / (7*3!) + ...)
... und hier das Näherungsprogramm:
WindowTitle " Asym-Erf(), die Gauss-Fehlerfunktion in asymptotischer Näherung "
' Quelle: http://jean-pierre.moreau.pagesperso-orange.fr/Basic/asymerf_bas.txt
' (D) Demo 2016/11 transponiert nach XProfan 11.2a by P. Specht, Vienna / Austria
' Keine wie auch immer geartete Gewähr! No warranty whatsoever!
'****************************************************
'* Program to demonstrate ASYMERF *
'* ------------------------------------------------ *
'* Reference: BASIC Scientific Subroutines, Vol. II *
'* by F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1].*
'* ------------------------------------------------ *
'* SAMPLE RUN: *
'* Find the value of ERF(X)=2*Exp(-X*X)/SQRT(PI) *
'* *
'* Input X ? 3 *
'* ERF(X)= .9999779 with error estimate= -.00000000 *
'* Number of terms evaluated was 10 *
'* *
'* Input X ? 4 *
'* ERF(X)= 1.0000000 with error estimate= 0.0000000 *
'* Number of terms evaluated was 17 *
'****************************************************
' DEFINT I-N : DEFDBL A-H, O-Z
WindowStyle 24:CLS:font 2:Declare x!,y!,e!,n&:Set("decimals",17)
Tests:
Print "\n\n Die Gauss-Fehlerfunktion Erf(x) für den Wert x = ";:Input x!
'Gosub "S1000"
S1000
Print
Print "\n Erf(x) für den Wert x= ";x!;" beträgt: ";format$("0.######",y!)
PRINT " mit einer Fehleabschätzung zu ";format$("##0.##########",e!)
PRINT
PRINT " ";n&;" Terme wurde berücksichtigt.";
WaitInput
Goto "Tests"
'***********************************************************
'* Asymptotic series expansion of the integral of *
'* 2 EXP(-X*X)/(X*SQRT(PI)), the normalized error function *
'* (ASYMERF). This program determines the values of the *
'* above integrand using an asymptotic series which is *
'* evaluated to the level of maximum accuracy. *
'* The integral is from 0 to X. The input parameter, X *
'* must be > 0. The results are returned in Y and Y1, *
'* with the error measure in E. The number of terms used *
'* is returned in N. The error is roughly equal to first *
'* term neglected in the series summation. *
'* ------------------------------------------------------- *
'* Reference: A short table of integrals by B.O. Peirce, *
'* Ginn and Company, 1957. *
'***********************************************************
Proc S1000
Declare c1!,c2!,y1!
n& = 1 : y! = 1 : c2! = 1 / (2 * Sqr(x!))
'G1100:
Repeat
y! = y! - c2!
n& = n& + 2: c1! = c2!
c2! = -c1! * n& / (2 * x! * x!)
'Test for divergence - The break point is roughly N=X*X
Case ABS(c2!) > Abs(c1!) : BREAK ':= Goto "G1200"
' Continue summation
Until 0 ':= Goto "G1100"
' G1200:
n& = (n& + 1) / 2
e! = EXP(-x! * x!) / (x! * 1.772453850905516)
y1! = y! * e!
y! = 1 - y1!
e! = e! * c2!
RETURN
'End of file Asymerf.prf
Alles anzeigen