1 18 19 package org.apache.commons.math.analysis; 20 21 import junit.framework.TestCase; 22 23 27 public class UnivariateRealFunctionUtilsTest extends TestCase { 28 31 public void testLocalMaximumCentered() { 32 UnivariateRealFunction function = new SinFunction(); 33 UnivariateRealFunction derivative = UnivariateRealFunctionUtils.centerDifferenceDerivative(function, 1.0e-5); 34 testLocalMaximum(derivative); 35 } 36 37 40 public void testLocalMaximumForward() { 41 UnivariateRealFunction function = new SinFunction(); 42 UnivariateRealFunction derivative = UnivariateRealFunctionUtils.forwardDifferenceDerivative(function, 1.0e-5); 43 testLocalMaximum(derivative); 44 } 45 46 49 public void testLocalMaximumBackward() { 50 UnivariateRealFunction function = new SinFunction(); 51 UnivariateRealFunction derivative = UnivariateRealFunctionUtils.backwardDifferenceDerivative(function, 1.0e-5); 52 testLocalMaximum(derivative); 53 } 54 55 58 private void testLocalMaximum(UnivariateRealFunction derivative) { 59 try { 60 double maximum = UnivariateRealSolverUtils.solve(derivative, Math.PI / 3.0, Math.PI * 2.0 / 3.0); 61 assertEquals(maximum, Math.PI / 2.0, 1.0e-5); 62 } catch (Exception ex) { 63 fail(ex.getMessage()); 64 } 65 } 66 } 67 | Popular Tags |