HarmonicOscillator implements UnivariateDifferentiableFunction, DifferentiableUnivariateFunction { public double value(double x) { return value(omega * x + phase, amplitude); } HarmonicOscillator(double amplitude,
                              double omega,
                              double phase); double value(double x); @Deprecated UnivariateFunction derivative(); DerivativeStructure value(final DerivativeStructure t);  }
@Test public void testSomeValues() { final double a = -1.2; final double w = 0.34; final double p = 5.6; final UnivariateFunction f = new HarmonicOscillator(a, w, p); final double d = 0.12345; for (int i = 0; i < 10; i++) { final double v = i * d; Assert.assertEquals(a * FastMath.cos(w * v + p), f.value(v), 0); } }
@Test(expected=NullArgumentException.class) public void testParametricUsage1() { final HarmonicOscillator.Parametric g = new HarmonicOscillator.Parametric(); g.value(0, null); }
@Test(expected=DimensionMismatchException.class) public void testParametricUsage2() { final HarmonicOscillator.Parametric g = new HarmonicOscillator.Parametric(); g.value(0, new double[] {0}); }
@Test public void testParametricValue() { final double amplitude = 2; final double omega = 3; final double phase = 4; final HarmonicOscillator f = new HarmonicOscillator(amplitude, omega, phase); final HarmonicOscillator.Parametric g = new HarmonicOscillator.Parametric(); Assert.assertEquals(f.value(-1), g.value(-1, new double[] {amplitude, omega, phase}), 0); Assert.assertEquals(f.value(0), g.value(0, new double[] {amplitude, omega, phase}), 0); Assert.assertEquals(f.value(2), g.value(2, new double[] {amplitude, omega, phase}), 0); }