Package org.apache.commons.math.analysis

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


    /**
     * Test the deprecated APIs.
     */
    @Deprecated
    public void testDeprecated() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealSolver solver = new RiddersSolver(f);
        double min, max, expected, result, tolerance;

        min = 3.0; max = 4.0; expected = Math.PI;
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
View Full Code Here


    /**
     * Test of solver for the sine function.
     */
    public void testSinFunction() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealSolver solver = new RiddersSolver();
        double min, max, expected, result, tolerance;

        min = 3.0; max = 4.0; expected = Math.PI;
        tolerance = Math.max(solver.getAbsoluteAccuracy(),
View Full Code Here

    /**
     * Test of parameters for the solver.
     */
    public void testParameters() throws Exception {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealSolver solver = new RiddersSolver();

        try {
            // bad interval
            solver.solve(f, 1, -1);
View Full Code Here

     * 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 NevilleInterpolator();
        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

     * 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

*/
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

        }
    }

    @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

    public LegendreGaussIntegratorTest(String name) {
        super(name);
    }

    public void testSinFunction() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        UnivariateRealIntegrator integrator = new LegendreGaussIntegrator(5, 64);
        integrator.setAbsoluteAccuracy(1.0e-10);
        integrator.setRelativeAccuracy(1.0e-14);
        integrator.setMinimalIterationCount(2);
        integrator.setMaximalIterationCount(15);
View Full Code Here

        } catch (IllegalArgumentException ex) {
            // expected
        }
        try {
            // bad function
            solver.solve(new SinFunction(), -1, 1);
            fail("Expecting IllegalArgumentException - bad function");
        } catch (IllegalArgumentException ex) {
            // expected
        }
    }
View Full Code Here

*/
public final class BisectionSolverTest extends TestCase {

    @Deprecated
    public void testDeprecated() throws MathException {
        UnivariateRealFunction f = new SinFunction();
        double result;

        UnivariateRealSolver solver = new BisectionSolver(f);
        result = solver.solve(3, 4);
        assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy());
View Full Code Here

TOP

Related Classes of org.apache.commons.math.analysis.SinFunction

Copyright © 2018 www.massapicom. 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.