I have a mathematical function as shown below
$$ (h+1) * U(k,h) = \sum_{r=0}^k \sum_{s=0}^h (r + 1) * (k - r + 1) * U(r + 1, h - s) * U(k - r + 1, s)\ + \sum_{r=0}^k \sum_{s=0}^h (k - r + 1) * (k - r + 2) * U(r, h - s) * U(k - r + 2, s)\,. $$
Base condition for U(k,h) is
$$ U(k,0) = (-1)^k/k! $$
I am using the following code to calculate the function
public double U(int k, int h) { h--; Int16 r, s; if (h == -1) { return (double)(Power(-1, k) / fact[k]); } else if (arr1[k, h] != 0 && arr2[k, h] != 0) return (double)((arr1[k, h] + arr2[k, h]) / (h + 1)); else { for (r = 0; r <= k; r++) { for (s = 0; s <= h; s++) { arr1[k,h] += (r + 1) * (k - r + 1) * U(r + 1, h - s) * U(k - r + 1, s); } } for (r = 0; r <= k; r++) { for (s = 0; s <= h; s++) { arr2[k,h] += (k - r + 1) * (k - r + 2) * U(r, h - s) * U(k - r + 2, s); } } return (double)((arr1[k,h] + arr2[k,h]) / (h + 1)); } }
The function works fine for values of k and h up to 40. After that it prints
at ndp.functions.U(Int32 k, Int32 h)
at ndp.functions.U(Int32 k, Int32 h)
It certainly prints more, if that's an exception message? We provide reviewing working code and suggestions for improvement. If you need debugging help, refer to Stack Overflow please and make sure to show the debugging efforts you've been already doing. \$\endgroup\$