/// <inheritdoc/> public double value(double[] x) { int n = x.Length; // delegate computation to underlying function DerivativeStructure[] dsX = new DerivativeStructure[n]; for (int i = 0; i < n; ++i) { if (i == k) { dsX[i] = new DerivativeStructure(1, 1, 0, x[i]); } else { dsX[i] = new DerivativeStructure(1, 1, x[i]); } } DerivativeStructure y = f.value(dsX); // extract partial derivative return(y.getPartialDerivative(1)); }
/// <inheritdoc/> public double[] value(double[] x) { int n = x.Length; // delegate computation to underlying function DerivativeStructure[] dsX = new DerivativeStructure[n]; for (int i = 0; i < n; ++i) { dsX[i] = new DerivativeStructure(n, 1, i, x[i]); } DerivativeStructure y = f.value(dsX); // extract gradient double[] gradient = new double[n]; int[] orders = new int[n]; for (int i = 0; i < n; ++i) { orders[i] = 1; gradient[i] = y.getPartialDerivative(orders); orders[i] = 0; } return(gradient); }