related to error function

  • Thread starter Thread starter amit saraf
  • Start date Start date
amit said:
How to find inverse of complementary error and error function

Hi. If you don't get a better solution, here is a Newton version
of the Inverse Error function. The normal Series equation converges too
slowly in my opinion.
Note that Excel's ERF() function can't work with Negative values (it's a
known bug). This tries to work around it.
As a simple test, we try to get back the same values...

Sub TestIt()
Debug.Print InverseERF([Erf(.1)])
Debug.Print InverseERF([Erf(.9)])
Debug.Print InverseERF([Erf(2)])
Debug.Print InverseERF([-Erf(2)])
End Sub


Function InverseERF(N)
Dim J As Long 'Counter
Dim G As Double 'Guess
Dim Ng As Double 'New Guess
Dim K As Double 'Constant
Dim M As Double 'Hold Positive value of n

Select Case N
Case -1
InverseERF = "-Infinity"
Case 1
InverseERF = "+Infinity"
Case -1 To 1
'Valid
With WorksheetFunction
K = [SqrtPi(1)/2]
Ng = 0.5
M = Abs(N)
Do
G = Ng
Ng = G + K * Exp(G * G) * (.ErfC(G) + M - 1)
J = J + 1
Loop While G <> Ng And J < 30
'It's a Odd function, so ok.
InverseERF = Sgn(N) * Ng
End With
Case Else
InverseERF = "Invalid"
End Select
End Function

- - -
HTH
Dana DeLouis
 
Use the relationship between these functions and functions for which Excel
does have inverses.
ERF(x) = GAMMADIST(x^2,0.5,1,TRUE)
ERFC(x) = 2*NORMSDIST(-x*SQRT(2)) = CHIDIST(2*x^2,1)
so
invERF(p) = SQRT(GAMMAINV(p,0.5,1))
invERFC(p) = -NORMSINV(p/2)/SQRT(2) = SQRT(CHIINV(p,1)/2)

For Excel 2003 or later, NORMSDIST and NORMSINV are much more accurate than
ERFC for large values of x. For earlier versions of Excel, CHIDIST is more
accurate than ERFC, but neither inverse function performs well for large x
(small p).

Jerry
 
Back
Top