Package org.jquantlib.math.interpolations

Examples of org.jquantlib.math.interpolations.LinearInterpolation


        QL.info("Testing use of interpolations as functors...");

        final Array x = new Array(new double[] { 0.0, 1.0, 2.0, 3.0, 4.0 });
        final Array y = new Array(new double[] { 5.0, 4.0, 3.0, 2.0, 1.0 });

        final Interpolation f = new LinearInterpolation(x, y);
        f.update();

        final Array x2 = new Array(new double[] { -2.0, -1.0, 0.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0 });
        final int N = x2.size();

        final double tolerance = 1.0e-12;

        // case 1: extrapolation not allowed
        try {
            final Array y2 = x2.clone().transform(f);
            System.out.println(y2);
            throw new NotThrown();
        } catch (final NotThrown ex) {
            throw new LibraryException("failed to throw exception when trying to extrapolate");
        } catch (final Exception ex) {
            // as expected, we are OK.
            System.out.println(ex);
        }

        // case 2: enable extrapolation
        f.enableExtrapolation();
        final Array y2 = x2.clone().transform(f);
        System.out.println(y2);
        for (int i=0; i<N-1; i++) {
            final double expected = 5.0 - x2.get(i);
            final double calculated = y2.get(i);
View Full Code Here


        QL.info("Testing use of interpolations as functors...");

        final Array x = new Array(new double[] { 0.0, 1.0, 2.0, 3.0, 4.0 });
        final Array y = new Array(new double[] { 5.0, 4.0, 3.0, 2.0, 1.0 });

        final Interpolation f = new LinearInterpolation(x, y);
        f.update();

        final Array x2 = new Array(new double[] { -2.0, -1.0, 0.0, 1.0, 3.0, 4.0, 5.0, 6.0, 7.0 });
        final int N = x2.size();

        final double tolerance = 1.0e-12;

        // case 1: extrapolation not allowed
        try {
            final Array y2 = x2.clone().transform(f);
            System.out.println(y2);
            throw new NotThrown();
        } catch (final NotThrown ex) {
            throw new LibraryException("failed to throw exception when trying to extrapolate");
        } catch (final Exception ex) {
            // as expected, we are OK.
            System.out.println(ex);
        }

        // case 2: enable extrapolation
        f.enableExtrapolation();
        final Array y2 = x2.clone().transform(f);
        System.out.println(y2);
        for (int i=0; i<N-1; i++) {
            final double expected = 5.0 - x2.get(i);
            final double calculated = y2.get(i);
View Full Code Here

    @Override
    public final int requiredPoints() { return 2; }

    @Override
    public Interpolation interpolate(final Array vx, final Array vy) /* @ReadOnly */{
        return new LinearInterpolation(vx, vy);
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.interpolations.LinearInterpolation

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.