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