Example usage for org.apache.commons.math3.analysis.solvers UnivariateSolverUtils isBracketing

List of usage examples for org.apache.commons.math3.analysis.solvers UnivariateSolverUtils isBracketing

Introduction

In this page you can find the example usage for org.apache.commons.math3.analysis.solvers UnivariateSolverUtils isBracketing.

Prototype

public static boolean isBracketing(UnivariateFunction function, final double lower, final double upper)
        throws NullArgumentException 

Source Link

Document

Check whether the interval bounds bracket a root.

Usage

From source file:fr.cs.examples.bodies.Phasing.java

/**
 * Find the state at which the reference latitude is crossed.
 * @param latitude latitude to search for
 * @param guessDate guess date for the crossing
 * @param endDate maximal date not to overtake
 * @param shift shift value used to evaluate the latitude function bracketing around the guess date
 * @param maxShift maximum value that the shift value can take
 * @param propagator propagator used// w  ww.j  a v  a 2s .  co m
 * @return state at latitude crossing time
 * @throws OrekitException if state cannot be propagated
 * @throws NoBracketingException if latitude cannot be bracketed in the search interval
 */
private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate,
        final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator)
        throws OrekitException, NoBracketingException {

    // function evaluating to 0 at latitude crossings
    final UnivariateFunction latitudeFunction = new UnivariateFunction() {
        /** {@inheritDoc} */
        public double value(double x) {
            try {
                final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
                final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
                final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
                return point.getLatitude() - latitude;
            } catch (OrekitException oe) {
                throw new RuntimeException(oe);
            }
        }
    };

    // try to bracket the encounter
    double span;
    if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
        // Take a 1e-3 security margin
        span = endDate.durationFrom(guessDate) - 1e-3;
    } else {
        span = shift;
    }

    while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {

        if (2 * span > maxShift) {
            // let the Apache Commons Math exception be thrown
            UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
        } else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
            // Out of range :
            return null;
        }

        // expand the search interval
        span *= 2;

    }

    // find the encounter in the bracketed interval
    final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
    final double dt = solver.solve(1000, latitudeFunction, -span, span);
    return propagator.propagate(guessDate.shiftedBy(dt));

}

From source file:org.orekit.utils.SecularAndHarmonicTest.java

private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate,
        final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator)
        throws OrekitException, NoBracketingException {

    // function evaluating to 0 at latitude crossings
    final UnivariateFunction latitudeFunction = new UnivariateFunction() {
        /** {@inheritDoc} */
        public double value(double x) {
            try {
                final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
                final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
                final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
                return point.getLatitude() - latitude;
            } catch (OrekitException oe) {
                throw new RuntimeException(oe);
            }/*from   w w  w.j  a  v a 2 s.c om*/
        }
    };

    // try to bracket the encounter
    double span;
    if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
        // Take a 1e-3 security margin
        span = endDate.durationFrom(guessDate) - 1e-3;
    } else {
        span = shift;
    }

    while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {

        if (2 * span > maxShift) {
            // let the Apache Commons Math exception be thrown
            UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
        } else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
            // Out of range :
            return null;
        }

        // expand the search interval
        span *= 2;

    }

    // find the encounter in the bracketed interval
    final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
    final double dt = solver.solve(1000, latitudeFunction, -span, span);
    return propagator.propagate(guessDate.shiftedBy(dt));

}