Scaled extra error function, erfcx (x), calculation eliminating arithmetic overflow - VBA / Excel

I need an algorithm / approximation to calculate the scaled extra error function, erfcx (x) for precision with a double float.

I am on a working computer, so I limited myself to using Excel and VBA, and I can not use external libraries or add-ons: I need to code this myself.

Excel provides only the erf () and erfc () functions.

The relationship erfcx (x) = exp (x ^ 2) erfc (x) is obviously useful, however there is over / underflow arithmetic for x greater than about 26.5, and I need to go more than that.

The article below discussed the implementation of python - but it does not seem to fix the problem from what I can say. It provides solutions using other libraries or an approximation that is not accurate enough for my needs.

Is scalable optional error function available in python?

Any suggestions?

Update:

I used this Continuation of fragmentation , which I found on Wikipedia
and a modified version of the algorithm for solving continued fractions found here http://finance4traders.blogspot.nl/2009/07/continued-fractions-and-modified-lentzs.html

The following code seems to work and actually requires fewer iterations for large input parameters.

Function erfcx(x) As Variant
Dim Ai As Double
Dim Bi As Double
Dim Ci As Double
Dim Di As Double
Dim Ei As Double
Dim Fi As Double
Dim X2 As Double
Dim i As Long

Const SQRPI As Double = 1.7724538509055
Const MAX_ITERATIONS = 1000


If x < 26.5 Then
    erfcx = Application.WorksheetFunction.ErfC_Precise(x) * Exp(x ^ 2)
Else
    X2 = x ^ 2
    Bi = X2
    Fi = X2
    Ci = X2
    Di = 0
    Do
        i = i + 1
        Ai = i / 2
        If i Mod 2 = 0 Then
            Bi = X2
        Else
            Bi = 1
        End If
        Di = 1 / (Bi + Ai * Di)
        Ci = Bi + Ai / Ci
        Ei = Ci * Di
        Fi = Fi * Ei
    Loop While Ei <> 1 And i < MAX_ITERATIONS
    Debug.Print i
    erfcx = x / Fi / SQRPI
End If  End function
+1
source share
1

:

AMS

, , , VBA UDF()

0

Source: https://habr.com/ru/post/1656272/


All Articles