@Override
public DerivativeStructure[] value(DerivativeStructure[] variables) {
DerivativeStructure[] f = new DerivativeStructure[m];
for (int i = 0; i < (m - 2); ++i) {
double div = (i + 1) / 29.0;
DerivativeStructure s1 = variables[0].getField().getZero();
DerivativeStructure dx = variables[0].getField().getOne();
for (int j = 1; j < n; ++j) {
s1 = s1.add(dx.multiply(j).multiply(variables[j]));
dx = dx.multiply(div);
}
DerivativeStructure s2 = variables[0].getField().getZero();
dx = variables[0].getField().getOne();
for (int j = 0; j < n; ++j) {
s2 = s2.add(dx.multiply(variables[j]));
dx = dx.multiply(div);
}
f[i] = s1.subtract(s2.multiply(s2)).subtract(1);
}
DerivativeStructure x1 = variables[0];
DerivativeStructure x2 = variables[1];
f[m - 2] = x1;
f[m - 1] = x2.subtract(x1.multiply(x1)).subtract(1);
return f;
}