User talk:NorwegianBlue/cpp program for calculating d3

Dear Mr. NorwegianBlue,

The calculation for d3 may be failing due to a small error in the program. By replacing alpha_1 with alpha_n and vice versa in the following line of d3 function, you may get the d3 value for given n up to 1 decimal place only. sum += (1 - std::pow(alpha_1,n) - std::pow(1 - alpha_n,n) + std::pow(alpha_1 - alpha_n, n))*dx_1*dx_n

I have written a program in VBA for the calculation of d3 values which gives accuracy up to 5 decimal places. Although the program is divided in three parts but it may be merged together in one single routine. You may translate it to C++. I am posting the code for your reference, hoping that we may work together to further improve the accuracy.

Function d3Const(ByVal n As Integer) As Double Dim result As Double Call d3fintegrate(-7, 7, -7, 1000, n, result) d3Const = result End Function

Private Sub d3fintegrate(ByVal a As Double, ByVal b As Double, ByVal c As Double, _                   ByVal subintervals As Integer, n As Integer, result As Double) Dim interval1 As Double, interval2 As Double, x As Double, y As Double Dim i As Integer, j As Integer interval1 = ((b - a) / subintervals) result = 0 i = 1 Do While (i <= subintervals) x = (a + (interval1 * (i - 0.5))) interval2 = ((x - c) / subintervals) j = 1 Do While (j <= subintervals) y = (c + (interval2 * (j - 0.5))) result = result + d3Intfunc(y, x, n) * interval1 * interval2 j = j + 1 Loop i = i + 1 Loop result = Sqr(2 * result - d2Const(n) ^ 2) End Sub

Private Function d3Intfunc(x As Double, y As Double, n As Integer) As Double Dim probx As Double, proby As Double probx = Application.NormSDist(x) proby = Application.NormSDist(y) d3Intfunc = (1 - (proby ^ n) - (1 - probx) ^ n + ((proby - probx) ^ n)) End Function

Function d3Const is the main program that calls the subroutine "d3fintegrate" which is then used for performing double integration of d3Intfunc. Ovclean (talk) 03:39, 26 January 2012 (UTC)