Examples of UnivariateRealFunction


Examples of org.apache.commons.math.analysis.UnivariateRealFunction

     * Test of interpolator for the exponential function.
     * <p>
     * |expm1^(n)(zeta)| <= e, zeta in [-1, 1]
     */
    public void testExpm1Function() throws MathException {
        UnivariateRealFunction f = new Expm1Function();
        UnivariateRealInterpolator interpolator = new NevilleInterpolator();
        double x[], y[], z, expected, result, tolerance;

        // 5 interpolating points on interval [-1, 1]
        int n = 5;
        double min = -1.0, max = 1.0;
        x = new double[n];
        y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = min + i * (max - min) / n;
            y[i] = f.value(x[i]);
        }
        double derivativebound = Math.E;
        UnivariateRealFunction p = interpolator.interpolate(x, y);

        z = 0.0; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);

        z = 0.5; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);

        z = -0.5; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);
    }
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

        try {
            // bad abscissas array
            double x[] = { 1.0, 2.0, 2.0, 4.0 };
            double y[] = { 0.0, 4.0, 4.0, 2.5 };
            UnivariateRealFunction p = interpolator.interpolate(x, y);
            p.value(0.0);
            fail("Expecting MathException - bad abscissas array");
        } catch (MathException ex) {
            // expected
        }
    }
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

     * Test of interpolator for the sine function.
     * <p>
     * |sin^(n)(zeta)| <= 1.0, zeta in [0, 2*PI]
     */
    public void testSinFunction() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
        double x[], y[], z, expected, result, tolerance;

        // 6 interpolating points on interval [0, 2*PI]
        int n = 6;
        double min = 0.0, max = 2 * Math.PI;
        x = new double[n];
        y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = min + i * (max - min) / n;
            y[i] = f.value(x[i]);
        }
        double derivativebound = 1.0;
        UnivariateRealFunction p = interpolator.interpolate(x, y);

        z = Math.PI / 4; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);

        z = Math.PI * 1.5; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);
    }
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

     * Test of interpolator for the exponential function.
     * <p>
     * |expm1^(n)(zeta)| <= e, zeta in [-1, 1]
     */
    public void testExpm1Function() throws MathException {
        UnivariateRealFunction f = new Expm1Function();
        UnivariateRealInterpolator interpolator = new DividedDifferenceInterpolator();
        double x[], y[], z, expected, result, tolerance;

        // 5 interpolating points on interval [-1, 1]
        int n = 5;
        double min = -1.0, max = 1.0;
        x = new double[n];
        y = new double[n];
        for (int i = 0; i < n; i++) {
            x[i] = min + i * (max - min) / n;
            y[i] = f.value(x[i]);
        }
        double derivativebound = Math.E;
        UnivariateRealFunction p = interpolator.interpolate(x, y);

        z = 0.0; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);

        z = 0.5; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);

        z = -0.5; expected = f.value(z); result = p.value(z);
        tolerance = Math.abs(derivativebound * partialerror(x, z));
        assertEquals(expected, result, tolerance);
    }
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

        try {
            // bad abscissas array
            double x[] = { 1.0, 2.0, 2.0, 4.0 };
            double y[] = { 0.0, 4.0, 4.0, 2.5 };
            UnivariateRealFunction p = interpolator.interpolate(x, y);
            p.value(0.0);
            fail("Expecting MathException - bad abscissas array");
        } catch (MathException ex) {
            // expected
        }
    }
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

*/
public final class BrentMinimizerTest {

    @Test
    public void testSinMin() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealOptimizer minimizer = new BrentOptimizer();
        minimizer.setMaxEvaluations(200);
        assertEquals(200, minimizer.getMaxEvaluations());
        try {
            minimizer.getResult();
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

    @Test
    public void testQuinticMin() throws MathException {
        // The quintic function has zeros at 0, +-0.5 and +-1.
        // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
        UnivariateRealFunction f = new QuinticFunction();
        UnivariateRealOptimizer minimizer = new BrentOptimizer();
        assertEquals(-0.27195613, minimizer.optimize(f, GoalType.MINIMIZE, -0.3, -0.2), 1.0e-8);
        assertEquals( 0.82221643, minimizer.optimize(f, GoalType.MINIMIZE,  0.30.9), 1.0e-8);
        assertTrue(minimizer.getIterationCount() <= 50);
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

    @Test
    public void testQuinticMax() throws MathException {
        // The quintic function has zeros at 0, +-0.5 and +-1.
        // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
        UnivariateRealFunction f = new QuinticFunction();
        UnivariateRealOptimizer minimizer = new BrentOptimizer();
        assertEquals(0.27195613, minimizer.optimize(f, GoalType.MAXIMIZE, 0.2, 0.3), 1.0e-8);
        minimizer.setMaximalIterationCount(30);
        try {
            minimizer.optimize(f, GoalType.MAXIMIZE, 0.2, 0.3);
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

        }
    }

    @Test
    public void testMinEndpoints() throws Exception {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealOptimizer solver = new BrentOptimizer();

        // endpoint is minimum
        double result = solver.optimize(f, GoalType.MINIMIZE, 3 * Math.PI / 2, 5);
        assertEquals(3 * Math.PI / 2, result, 70 * solver.getAbsoluteAccuracy());
 
View Full Code Here

Examples of org.apache.commons.math.analysis.UnivariateRealFunction

        return null;
    }

    @Override
    public double value(double x) throws FunctionEvaluationException {
        UnivariateRealFunction seg = getSegmentFor(x);
        if(seg == null){
            throw new FunctionEvaluationException(x, "Argument outside domain: " + x);
        }
           
        return seg.value(x);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.