HarmonicOscillator implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { @Deprecated public UnivariateFunction derivative() { return FunctionUtils.toDifferentiableUnivariateFunction(this).derivative(); } HarmonicOscillator(double amplitude,
                              double omega,
                              double phase); double value(double x); @Deprecated UnivariateFunction derivative(); DerivativeStructure value(final DerivativeStructure t);  }
@Test public void testDerivative() { final double a = -1.2; final double w = 0.34; final double p = 5.6; final HarmonicOscillator f = new HarmonicOscillator(a, w, p); for (int maxOrder = 0; maxOrder < 6; ++maxOrder) { final double d = 0.12345; for (int i = 0; i < 10; i++) { final double v = i * d; final DerivativeStructure h = f.value(new DerivativeStructure(1, maxOrder, 0, v)); for (int k = 0; k <= maxOrder; ++k) { final double trigo; switch (k % 4) { case 0: trigo = +FastMath.cos(w * v + p); break; case 1: trigo = -FastMath.sin(w * v + p); break; case 2: trigo = -FastMath.cos(w * v + p); break; default: trigo = +FastMath.sin(w * v + p); break; } Assert.assertEquals(a * FastMath.pow(w, k) * trigo, h.getPartialDerivative(k), Precision.EPSILON); } } } }