public static double Durbin(int n, double d)
{
double s;
int k = (int)(n * d) + 1;
int m = 2 * k - 1;
double h = k - n * d;
double[,] H = new double[m, m];
double[,] Q = new double[m, m];
double[,] B = new double[m, m];
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++)
if (i - j + 1 >= 0)
H[i, j] = 1;
for (int i = 0; i < m; i++)
{
H[i, 0] -= Math.Pow(h, i + 1);
H[m - 1, i] -= Math.Pow(h, m - i);
}
H[m - 1, 0] += (2 * h - 1 > 0 ? Math.Pow(2 * h - 1, m) : 0);
for (int i = 0; i < m; i++)
for (int j = 0; j < m; j++)
if (i - j + 1 > 0)
for (int g = 1; g <= i - j + 1; g++)
H[i, j] /= g;
int pQ = 0;
matrixPower(H, 0, Q, ref pQ, m, n, B);
s = Q[k - 1, k - 1];
for (int i = 1; i <= n; i++)
{
s *= (double)i / n;
if (s < 1.0e-140)
{
s *= 1.0e140;
pQ -= 140;
}
}
return s * Math.Pow(10.0, pQ);
}