3d * FastMath.PI / 2d,
11d * FastMath.PI / 6d,
2.d * FastMath.PI };
double y[] = { 0d, 0.5d, 1d, 0.5d, 0d, -0.5d, -1d, -0.5d, 0d };
UnivariateInterpolator i = new SplineInterpolator();
UnivariateFunction f = i.interpolate(x, y);
verifyInterpolation(f, x, y);
verifyConsistency((PolynomialSplineFunction) f, x);
/* Check coefficients against values computed using R (version 1.8.1, Red Hat Linux 9)
*
* To replicate in R:
* x[1] <- 0
* x[2] <- pi / 6, etc, same for y[] (could use y <- scan() for y values)
* g <- splinefun(x, y, "natural")
* splinecoef <- eval(expression(z), envir = environment(g))
* print(splinecoef)
*/
PolynomialFunction polynomials[] = ((PolynomialSplineFunction) f).getPolynomials();
double target[] = {y[0], 1.002676d, 0d, -0.17415829d};
TestUtils.assertEquals(polynomials[0].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[1], 8.594367e-01, -2.735672e-01, -0.08707914};
TestUtils.assertEquals(polynomials[1].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[2], 1.471804e-17,-5.471344e-01, 0.08707914};
TestUtils.assertEquals(polynomials[2].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[3], -8.594367e-01, -2.735672e-01, 0.17415829};
TestUtils.assertEquals(polynomials[3].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[4], -1.002676, 6.548562e-17, 0.17415829};
TestUtils.assertEquals(polynomials[4].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[5], -8.594367e-01, 2.735672e-01, 0.08707914};
TestUtils.assertEquals(polynomials[5].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[6], 3.466465e-16, 5.471344e-01, -0.08707914};
TestUtils.assertEquals(polynomials[6].getCoefficients(), target, sineCoefficientTolerance);
target = new double[]{y[7], 8.594367e-01, 2.735672e-01, -0.17415829};
TestUtils.assertEquals(polynomials[7].getCoefficients(), target, sineCoefficientTolerance);
//Check interpolation
Assert.assertEquals(FastMath.sqrt(2d) / 2d,f.value(FastMath.PI/4d),sineInterpolationTolerance);
Assert.assertEquals(FastMath.sqrt(2d) / 2d,f.value(3d*FastMath.PI/4d),sineInterpolationTolerance);
}