Search in sources :

Example 11 with FiniteDifferencesDifferentiator

use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.

the class FieldEquinoctialOrbitTest method differentiate.

private <T extends RealFieldElement<T>, S extends Function<FieldEquinoctialOrbit<T>, T>> double differentiate(TimeStampedFieldPVCoordinates<T> pv, Frame frame, double mu, S picker) {
    final DSFactory factory = new DSFactory(1, 1);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
    UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            return picker.apply(new FieldEquinoctialOrbit<>(pv.shiftedBy(dt), frame, mu)).getReal();
        }
    });
    return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Example 12 with FiniteDifferencesDifferentiator

use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.

the class FieldKeplerianOrbitTest method differentiate.

private <T extends RealFieldElement<T>, S extends Function<FieldKeplerianOrbit<T>, T>> double differentiate(TimeStampedFieldPVCoordinates<T> pv, Frame frame, double mu, S picker) {
    final DSFactory factory = new DSFactory(1, 1);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
    UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            return picker.apply(new FieldKeplerianOrbit<>(pv.shiftedBy(dt), frame, mu)).getReal();
        }
    });
    return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Example 13 with FiniteDifferencesDifferentiator

use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.

the class KeplerianOrbitTest method differentiate.

private <S extends Function<KeplerianOrbit, Double>> double differentiate(KeplerianOrbit orbit, S picker) {
    final DSFactory factory = new DSFactory(1, 1);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 0.1);
    UnivariateDifferentiableFunction diff = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            return picker.apply(orbit.shiftedBy(dt));
        }
    });
    return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Example 14 with FiniteDifferencesDifferentiator

use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.

the class OneAxisEllipsoidTest method testMovingGeodeticPoint.

@Test
public void testMovingGeodeticPoint() throws OrekitException {
    final OneAxisEllipsoid earth = new OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS, Constants.WGS84_EARTH_FLATTENING, FramesFactory.getITRF(IERSConventions.IERS_2010, true));
    double lat0 = FastMath.toRadians(60.0);
    double lon0 = FastMath.toRadians(25.0);
    double alt0 = 100.0;
    double lat1 = 1.0e-3;
    double lon1 = -2.0e-3;
    double alt1 = 1.2;
    double lat2 = -1.0e-5;
    double lon2 = -3.0e-5;
    double alt2 = -0.01;
    final DSFactory factory = new DSFactory(1, 2);
    final DerivativeStructure latDS = factory.build(lat0, lat1, lat2);
    final DerivativeStructure lonDS = factory.build(lon0, lon1, lon2);
    final DerivativeStructure altDS = factory.build(alt0, alt1, alt2);
    // direct computation of position, velocity and acceleration
    PVCoordinates pv = new PVCoordinates(earth.transform(new FieldGeodeticPoint<>(latDS, lonDS, altDS)));
    // finite differences computation
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 0.1);
    UnivariateDifferentiableFunction fx = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            GeodeticPoint gp = new GeodeticPoint(latDS.taylor(dt), lonDS.taylor(dt), altDS.taylor(dt));
            return earth.transform(gp).getX();
        }
    });
    UnivariateDifferentiableFunction fy = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            GeodeticPoint gp = new GeodeticPoint(latDS.taylor(dt), lonDS.taylor(dt), altDS.taylor(dt));
            return earth.transform(gp).getY();
        }
    });
    UnivariateDifferentiableFunction fz = differentiator.differentiate(new UnivariateFunction() {

        public double value(double dt) {
            GeodeticPoint gp = new GeodeticPoint(latDS.taylor(dt), lonDS.taylor(dt), altDS.taylor(dt));
            return earth.transform(gp).getZ();
        }
    });
    DerivativeStructure dtZero = factory.variable(0, 0.0);
    DerivativeStructure xDS = fx.value(dtZero);
    DerivativeStructure yDS = fy.value(dtZero);
    DerivativeStructure zDS = fz.value(dtZero);
    Assert.assertEquals(xDS.getValue(), pv.getPosition().getX(), 2.0e-20 * FastMath.abs(xDS.getValue()));
    Assert.assertEquals(xDS.getPartialDerivative(1), pv.getVelocity().getX(), 2.0e-12 * FastMath.abs(xDS.getPartialDerivative(1)));
    Assert.assertEquals(xDS.getPartialDerivative(2), pv.getAcceleration().getX(), 2.0e-9 * FastMath.abs(xDS.getPartialDerivative(2)));
    Assert.assertEquals(yDS.getValue(), pv.getPosition().getY(), 2.0e-20 * FastMath.abs(yDS.getValue()));
    Assert.assertEquals(yDS.getPartialDerivative(1), pv.getVelocity().getY(), 2.0e-12 * FastMath.abs(yDS.getPartialDerivative(1)));
    Assert.assertEquals(yDS.getPartialDerivative(2), pv.getAcceleration().getY(), 2.0e-9 * FastMath.abs(yDS.getPartialDerivative(2)));
    Assert.assertEquals(zDS.getValue(), pv.getPosition().getZ(), 2.0e-20 * FastMath.abs(zDS.getValue()));
    Assert.assertEquals(zDS.getPartialDerivative(1), pv.getVelocity().getZ(), 2.0e-12 * FastMath.abs(zDS.getPartialDerivative(1)));
    Assert.assertEquals(zDS.getPartialDerivative(2), pv.getAcceleration().getZ(), 2.0e-9 * FastMath.abs(zDS.getPartialDerivative(2)));
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) PVCoordinates(org.orekit.utils.PVCoordinates) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

Example 15 with FiniteDifferencesDifferentiator

use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.

the class Differentiation method differentiate.

/**
 * Differentiate a scalar function using finite differences.
 * @param function function to differentiate
 * @param driver driver for the parameter
 * @param nbPoints number of points used for finite differences
 * @param step step for finite differences
 * @return scalar function evaluating to the derivative of the original function
 */
public static ParameterFunction differentiate(final ParameterFunction function, final ParameterDriver driver, final int nbPoints, final double step) {
    final UnivariateFunction uf = new UnivariateFunction() {

        /**
         * {@inheritDoc}
         */
        @Override
        public double value(final double normalizedValue) throws OrekitExceptionWrapper {
            try {
                final double saved = driver.getNormalizedValue();
                driver.setNormalizedValue(normalizedValue);
                final double functionValue = function.value(driver);
                driver.setNormalizedValue(saved);
                return functionValue;
            } catch (OrekitException oe) {
                throw new OrekitExceptionWrapper(oe);
            }
        }
    };
    final FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(nbPoints, step);
    final UnivariateDifferentiableFunction differentiated = differentiator.differentiate(uf);
    return new ParameterFunction() {

        /**
         * {@inheritDoc}
         */
        @Override
        public double value(final ParameterDriver parameterDriver) throws OrekitException {
            if (!parameterDriver.getName().equals(driver.getName())) {
                throw new OrekitException(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, parameterDriver.getName(), driver.getName());
            }
            try {
                final DerivativeStructure dsParam = FACTORY.variable(0, parameterDriver.getNormalizedValue());
                final DerivativeStructure dsValue = differentiated.value(dsParam);
                return dsValue.getPartialDerivative(1);
            } catch (OrekitExceptionWrapper oew) {
                throw oew.getException();
            }
        }
    };
}
Also used : OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) UnivariateDifferentiableFunction(org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction) OrekitException(org.orekit.errors.OrekitException) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)

Aggregations

FiniteDifferencesDifferentiator (org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator)27 DSFactory (org.hipparchus.analysis.differentiation.DSFactory)25 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)19 DerivativeStructure (org.hipparchus.analysis.differentiation.DerivativeStructure)16 UnivariateDifferentiableFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction)16 Test (org.junit.Test)11 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)7 UnivariateDifferentiableVectorFunction (org.hipparchus.analysis.differentiation.UnivariateDifferentiableVectorFunction)6 OrekitException (org.orekit.errors.OrekitException)5 UnivariateVectorFunction (org.hipparchus.analysis.UnivariateVectorFunction)4 GeodeticPoint (org.orekit.bodies.GeodeticPoint)4 AbsoluteDate (org.orekit.time.AbsoluteDate)4 TimeScale (org.orekit.time.TimeScale)4 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)3 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)3 RandomGenerator (org.hipparchus.random.RandomGenerator)3 Well19937a (org.hipparchus.random.Well19937a)3 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)3 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)3 Frame (org.orekit.frames.Frame)3