Package org.apache.commons.math3.fraction

Examples of org.apache.commons.math3.fraction.BigFraction


    /**
     * @see BigFraction#BigFraction(int)
     */
    public Rational(int num) {
        fraction = new BigFraction(num);
    }
View Full Code Here


    /**
     * @see BigFraction#BigFraction(int, int)
     */
    public Rational(int num, int den) {
        fraction = new BigFraction(num, den);
    }
View Full Code Here

    /**
     * @see BigFraction#BigFraction(long)
     */
    public Rational(long num) {
        fraction = new BigFraction(num);
    }
View Full Code Here

    /**
     * @see BigFraction#BigFraction(long, long)
     */
    public Rational(long num, long den) {
        fraction = new BigFraction(num, den);
    }
View Full Code Here

public class FieldHermiteInterpolatorTest {

    @Test
    public void testZero() {
        FieldHermiteInterpolator<BigFraction> interpolator = new FieldHermiteInterpolator<BigFraction>();
        interpolator.addSamplePoint(new BigFraction(0), new BigFraction[] { new BigFraction(0) });
        for (int x = -10; x < 10; x++) {
            BigFraction y = interpolator.value(new BigFraction(x))[0];
            Assert.assertEquals(BigFraction.ZERO, y);
            BigFraction[][] derivatives = interpolator.derivatives(new BigFraction(x), 1);
            Assert.assertEquals(BigFraction.ZERO, derivatives[0][0]);
            Assert.assertEquals(BigFraction.ZERO, derivatives[1][0]);
        }
    }
View Full Code Here

    }

    @Test
    public void testQuadratic() {
        FieldHermiteInterpolator<BigFraction> interpolator = new FieldHermiteInterpolator<BigFraction>();
        interpolator.addSamplePoint(new BigFraction(0), new BigFraction[] { new BigFraction(2) });
        interpolator.addSamplePoint(new BigFraction(1), new BigFraction[] { new BigFraction(0) });
        interpolator.addSamplePoint(new BigFraction(2), new BigFraction[] { new BigFraction(0) });
        for (double x = -10; x < 10; x += 1.0) {
            BigFraction y = interpolator.value(new BigFraction(x))[0];
            Assert.assertEquals((x - 1) * (x - 2), y.doubleValue(), 1.0e-15);
            BigFraction[][] derivatives = interpolator.derivatives(new BigFraction(x), 3);
            Assert.assertEquals((x - 1) * (x - 2), derivatives[0][0].doubleValue(), 1.0e-15);
            Assert.assertEquals(2 * x - 3, derivatives[1][0].doubleValue(), 1.0e-15);
            Assert.assertEquals(2, derivatives[2][0].doubleValue(), 1.0e-15);
            Assert.assertEquals(0, derivatives[3][0].doubleValue(), 1.0e-15);
        }
View Full Code Here

    }

    @Test
    public void testMixedDerivatives() {
        FieldHermiteInterpolator<BigFraction> interpolator = new FieldHermiteInterpolator<BigFraction>();
        interpolator.addSamplePoint(new BigFraction(0), new BigFraction[] { new BigFraction(1) }, new BigFraction[] { new BigFraction(2) });
        interpolator.addSamplePoint(new BigFraction(1), new BigFraction[] { new BigFraction(4) });
        interpolator.addSamplePoint(new BigFraction(2), new BigFraction[] { new BigFraction(5) }, new BigFraction[] { new BigFraction(2) });
        BigFraction[][] derivatives = interpolator.derivatives(new BigFraction(0), 5);
        Assert.assertEquals(new BigFraction1), derivatives[0][0]);
        Assert.assertEquals(new BigFraction2), derivatives[1][0]);
        Assert.assertEquals(new BigFraction8), derivatives[2][0]);
        Assert.assertEquals(new BigFraction(-24), derivatives[3][0]);
        Assert.assertEquals(new BigFraction( 24), derivatives[4][0]);
        Assert.assertEquals(new BigFraction0), derivatives[5][0]);
        derivatives = interpolator.derivatives(new BigFraction(1), 5);
        Assert.assertEquals(new BigFraction4), derivatives[0][0]);
        Assert.assertEquals(new BigFraction2), derivatives[1][0]);
        Assert.assertEquals(new BigFraction( -4), derivatives[2][0]);
        Assert.assertEquals(new BigFraction0), derivatives[3][0]);
        Assert.assertEquals(new BigFraction( 24), derivatives[4][0]);
        Assert.assertEquals(new BigFraction0), derivatives[5][0]);
        derivatives = interpolator.derivatives(new BigFraction(2), 5);
        Assert.assertEquals(new BigFraction5), derivatives[0][0]);
        Assert.assertEquals(new BigFraction2), derivatives[1][0]);
        Assert.assertEquals(new BigFraction8), derivatives[2][0]);
        Assert.assertEquals(new BigFraction( 24), derivatives[3][0]);
        Assert.assertEquals(new BigFraction( 24), derivatives[4][0]);
        Assert.assertEquals(new BigFraction0), derivatives[5][0]);
    }
View Full Code Here

    @Test
    public void testWikipedia() {
        // this test corresponds to the example from Wikipedia page:
        // http://en.wikipedia.org/wiki/Hermite_interpolation
        FieldHermiteInterpolator<BigFraction> interpolator = new FieldHermiteInterpolator<BigFraction>();
        interpolator.addSamplePoint(new BigFraction(-1),
                                    new BigFraction[] { new BigFraction( 2) },
                                    new BigFraction[] { new BigFraction(-8) },
                                    new BigFraction[] { new BigFraction(56) });
        interpolator.addSamplePoint(new BigFraction( 0),
                                    new BigFraction[] { new BigFraction( 1) },
                                    new BigFraction[] { new BigFraction( 0) },
                                    new BigFraction[] { new BigFraction( 0) });
        interpolator.addSamplePoint(new BigFraction( 1),
                                    new BigFraction[] { new BigFraction( 2) },
                                    new BigFraction[] { new BigFraction( 8) },
                                    new BigFraction[] { new BigFraction(56) });
        for (BigFraction x = new BigFraction(-1); x.doubleValue() <= 1.0; x = x.add(new BigFraction(1, 8))) {
            BigFraction y = interpolator.value(x)[0];
            BigFraction x2 = x.multiply(x);
            BigFraction x4 = x2.multiply(x2);
            BigFraction x8 = x4.multiply(x4);
            Assert.assertEquals(x8.add(new BigFraction(1)), y);
        }
    }
View Full Code Here

    }

    @Test
    public void testOnePointParabola() {
        FieldHermiteInterpolator<BigFraction> interpolator = new FieldHermiteInterpolator<BigFraction>();
        interpolator.addSamplePoint(new BigFraction(0),
                                    new BigFraction[] { new BigFraction(1) },
                                    new BigFraction[] { new BigFraction(1) },
                                    new BigFraction[] { new BigFraction(2) });
        for (BigFraction x = new BigFraction(-1); x.doubleValue() <= 1.0; x = x.add(new BigFraction(1, 8))) {
            BigFraction y = interpolator.value(x)[0];
            Assert.assertEquals(BigFraction.ONE.add(x.multiply(BigFraction.ONE.add(x))), y);
        }
    }
View Full Code Here

    }

    @Test(expected=IllegalArgumentException.class)
    public void testDuplicatedAbscissa() {
        FieldHermiteInterpolator<BigFraction> interpolator = new FieldHermiteInterpolator<BigFraction>();
        interpolator.addSamplePoint(new BigFraction(1), new BigFraction[] { new BigFraction(0) });
        interpolator.addSamplePoint(new BigFraction(1), new BigFraction[] { new BigFraction(1) });
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.math3.fraction.BigFraction

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.