* y = 2 x<sub>1</sub><sup>2</sup> - 3 x<sub>2</sub><sup>2</sup>
* + 4 x<sub>1</sub> x<sub>2</sub> - 5
*/
@Test
public void testParaboloid2D() throws MathException {
MultivariateRealFunction f = new MultivariateRealFunction() {
public double value(double[] x) {
if (x.length != 2) {
throw new IllegalArgumentException();
}
return 2 * x[0] * x[0] - 3 * x[1] * x[1] + 4 * x[0] * x[1] - 5;
}
};
MultivariateRealInterpolator interpolator = new MicrosphereInterpolator();
// Interpolating points in [-10, 10][-10, 10] by steps of 2.
final int n = 121;
final int dim = 2;
double[][] x = new double[n][dim];
double[] y = new double[n];
int index = 0;
for (int i = -10; i <= 10; i += 2) {
for (int j = -10; j <= 10; j += 2) {
x[index][0] = i;
x[index][1] = j;
y[index] = f.value(x[index]);
++index;
}
}
MultivariateRealFunction p = interpolator.interpolate(x, y);
double[] c = new double[dim];
double expected, result;
c[0] = 0;
c[1] = 0;
expected = f.value(c);
result = p.value(c);
Assert.assertEquals("On sample point", expected, result, Math.ulp(1d));
c[0] = 2 + 1e-5;
c[1] = 2 - 1e-5;
expected = f.value(c);
result = p.value(c);
Assert.assertEquals("1e-5 away from sample point", expected, result, 1e-3);
}