private NMMatrix Jacobian(NVector p, NVector y) { NVector ps = new NVector(p); //save a copy NMMatrix J = new NMMatrix(m, n); //creating a new J from scratch double del_p; for (int j = 0; j < n; j++) { del_p = Math.Max(dp[j] * Math.Abs(p[j]), dp[j]); p[j] = ps[j] + del_p; NVector y1 = func(t, p); if (dp[j] != 0D) //forward or backward difference J.ReplaceColumn(j, (y1 - y) / del_p); else //central difference { p[j] = ps[j] - del_p; J.ReplaceColumn(j, (y1 - func(t, p)) / (2D * del_p)); } p[j] = ps[j]; //restore this value } return J; }