Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
How about we get rid of Excel's erf, and use our own?
This is much more accurate. I've eliminated WorksheetFunction also. Not much Error checking, but this should give you some ideas. HTH. :) Option Explicit Const SqrPi As Double = 1.77245385090552 Sub TestIt() Debug.Print InverseErf(0.1) Debug.Print InverseErf(0.5) Debug.Print InverseErf(0.9) End Sub Function InverseErf(n) If n < 0 Or n = 1 Then Exit Function Dim g As Double Dim j As Long g = 0 For j = 1 To 15 g = g + (Exp(g * g) * SqrPi * (n - Erf(g))) / 2 Next j InverseErf = g End Function Function Erf(z) Dim k As Long Dim F As Double '(F)actorial Dim n As Double Dim d As Double Dim Ans As Double If z = 0 Then Exit Function F = 1 With WorksheetFunction For k = 0 To 25 n = (-1) ^ k * z ^ (2 * k + 1) d = F * (2 * k + 1) Ans = Ans + n / d F = F * (k + 1) Next k Ans = Ans * 2 / SqrPi End With Erf = Ans End Function -- HTH :) Dana DeLouis Windows XP & Excel 2007 "Wan" wrote in message ... How can I find an inverse error function on Excel, using functions that are available? |
#2
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
OOps! Forgot to remove Worksheetfunction.
Option Explicit Const SqrPi As Double = 1.77245385090552 Sub TestIt() Debug.Print InverseErf(0.1) Debug.Print InverseErf(0.5) Debug.Print InverseErf(0.9) End Sub Function InverseErf(n) If n < 0 Or n = 1 Then Exit Function Dim g As Double Dim j As Long g = 0 For j = 1 To 15 g = g + (Exp(g * g) * SqrPi * (n - Erf(g))) / 2 Next j InverseErf = g End Function Function Erf(z) Dim k As Long Dim F As Double '(F)actorial Dim n As Double Dim d As Double Dim Ans As Double If z = 0 Then Exit Function F = 1 For k = 0 To 25 n = (-1) ^ k * z ^ (2 * k + 1) d = F * (2 * k + 1) Ans = Ans + n / d F = F * (k + 1) Next k Erf = Ans * 2 / SqrPi End Function -- HTH :) Dana DeLouis |
#3
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
"Dana DeLouis" wrote...
.... Function InverseErf(n) If n < 0 Or n = 1 Then Exit Function Dim g As Double Dim j As Long g = 0 For j = 1 To 15 g = g + (Exp(g * g) * SqrPi * (n - Erf(g))) / 2 Next j InverseErf = g End Function Function Erf(z) Dim k As Long Dim F As Double '(F)actorial Dim n As Double Dim d As Double Dim Ans As Double If z = 0 Then Exit Function F = 1 For k = 0 To 25 n = (-1) ^ k * z ^ (2 * k + 1) d = F * (2 * k + 1) Ans = Ans + n / d F = F * (k + 1) Next k Erf = Ans * 2 / SqrPi End Function .... Someone's gotta ask, since ERF(x) = 2*NORMSDIST(x*SQRT(2))-1, then why not use NORMSINV? That is, why not estimate InverseERF(y) as =NORMSINV((y+1)/2)/SQRT(2) ..'InverseErf [0.1] ..'0.0888559904942577 =NORMSINV((0.1+1)/2)/SQRT(2) - 0.0888559904942577 ..'InverseErf [0.5] ..'0.4769362762044698 =NORMSINV((0.5+1)/2)/SQRT(2) - 0.47693627620447 ..'InverseErf [0.9] ..'1.163087153676674 =NORMSINV((0.9+1)/2)/SQRT(2) - 1.16308715367667 |
#4
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
InverseERF(y) as
=NORMSINV((y+1)/2)/SQRT(2) Well, this is embarrassing! Thank you very much. :) -- Dana DeLouis "Harlan Grove" wrote in message ... "Dana DeLouis" wrote... ... .. since ERF(x) = 2*NORMSDIST(x*SQRT(2))-1, then why not use NORMSINV? That is, why not estimate InverseERF(y) as =NORMSINV((y+1)/2)/SQRT(2) ..'InverseErf [0.1] ..'0.0888559904942577 =NORMSINV((0.1+1)/2)/SQRT(2) - 0.0888559904942577 |
#5
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
You could avoid loss of precision for small erf values by using
SQRT(inv_gamma(erf_value,0.5,1)) where inv_gamma is the highly accurate equivalent of GAMMAINV from Ian Smith's VBA library http://members.aol.com/iandjmsmith/Examples.xls Unfortunately, the native GAMMAINV function is very crude for the purpose. Sorry to come so late to the party, but Google's indexing of newsgroups was down for nearly half a month, so I just stumbled onto this thread. Jerry "Harlan Grove" wrote: Someone's gotta ask, since ERF(x) = 2*NORMSDIST(x*SQRT(2))-1, then why not use NORMSINV? That is, why not estimate InverseERF(y) as =NORMSINV((y+1)/2)/SQRT(2) ..'InverseErf [0.1] ..'0.0888559904942577 =NORMSINV((0.1+1)/2)/SQRT(2) - 0.0888559904942577 ..'InverseErf [0.5] ..'0.4769362762044698 =NORMSINV((0.5+1)/2)/SQRT(2) - 0.47693627620447 ..'InverseErf [0.9] ..'1.163087153676674 =NORMSINV((0.9+1)/2)/SQRT(2) - 1.16308715367667 |
#6
![]()
Posted to microsoft.public.excel.worksheet.functions
|
|||
|
|||
![]()
"Jerry W. Lewis" wrote:
You could avoid loss of precision for small erf values by using SQRT(inv_gamma(erf_value,0.5,1)) where inv_gamma is the highly accurate equivalent of GAMMAINV from Ian Smith's VBA library http://members.aol.com/iandjmsmith/Examples.xls Unfortunately, the native GAMMAINV function is very crude for the purpose. The improvment in the inversion algorithm introduced in Excel 2003 means that GAMMAIN for Excel 2003 or later appears to give at least 6-figure accuracy, which may be adequate. Jerry |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
TAN INVERSE ? | Excel Worksheet Functions | |||
FFT INVERSE ANALYSIS | Excel Discussion (Misc queries) | |||
What is the Function for Inverse sin | Excel Worksheet Functions | |||
log inverse | Excel Discussion (Misc queries) | |||
Inverse sin | Excel Worksheet Functions |