Search in sources :

Example 26 with FiniteDifferencesDifferentiator

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

the class PVCoordinatesTest method testCrossProduct.

@Test
public void testCrossProduct() {
    DSFactory factory = new DSFactory(1, 2);
    RandomGenerator generator = new Well19937a(0x85c592b3be733d23l);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
    for (int i = 0; i < 200; ++i) {
        final PVCoordinates pv1 = randomPVCoordinates(generator, 1.0, 1.0, 1.0);
        final PVCoordinates pv2 = randomPVCoordinates(generator, 1.0, 1.0, 1.0);
        DerivativeStructure x = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getX();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getY();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return Vector3D.crossProduct(pv1.shiftedBy(t).getPosition(), pv2.shiftedBy(t).getPosition()).getZ();
            }
        }).value(factory.variable(0, 0.0));
        PVCoordinates product = PVCoordinates.crossProduct(pv1, pv2);
        Assert.assertEquals(x.getValue(), product.getPosition().getX(), 1.0e-16);
        Assert.assertEquals(y.getValue(), product.getPosition().getY(), 1.0e-16);
        Assert.assertEquals(z.getValue(), product.getPosition().getZ(), 1.0e-16);
        Assert.assertEquals(x.getPartialDerivative(1), product.getVelocity().getX(), 9.0e-10);
        Assert.assertEquals(y.getPartialDerivative(1), product.getVelocity().getY(), 9.0e-10);
        Assert.assertEquals(z.getPartialDerivative(1), product.getVelocity().getZ(), 9.0e-10);
        Assert.assertEquals(x.getPartialDerivative(2), product.getAcceleration().getX(), 3.0e-9);
        Assert.assertEquals(y.getPartialDerivative(2), product.getAcceleration().getY(), 3.0e-9);
        Assert.assertEquals(z.getPartialDerivative(2), product.getAcceleration().getZ(), 3.0e-9);
    }
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

Example 27 with FiniteDifferencesDifferentiator

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

the class FieldPVCoordinatesTest method testNormalize.

@Test
public void testNormalize() {
    DSFactory factory = new DSFactory(1, 2);
    RandomGenerator generator = new Well19937a(0x7ede9376e4e1ab5al);
    FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
    for (int i = 0; i < 200; ++i) {
        final FieldPVCoordinates<DerivativeStructure> pv = randomPVCoordinates(generator, 1e6, 1e3, 1.0);
        DerivativeStructure x = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getX().getValue();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getY().getValue();
            }
        }).value(factory.variable(0, 0.0));
        DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {

            public double value(double t) {
                return pv.shiftedBy(t).getPosition().normalize().getZ().getValue();
            }
        }).value(factory.variable(0, 0.0));
        FieldPVCoordinates<DerivativeStructure> normalized = pv.normalize();
        Assert.assertEquals(x.getValue(), normalized.getPosition().getX().getValue(), 1.0e-16);
        Assert.assertEquals(y.getValue(), normalized.getPosition().getY().getValue(), 1.0e-16);
        Assert.assertEquals(z.getValue(), normalized.getPosition().getZ().getValue(), 1.0e-16);
        Assert.assertEquals(x.getPartialDerivative(1), normalized.getVelocity().getX().getValue(), 3.0e-13);
        Assert.assertEquals(y.getPartialDerivative(1), normalized.getVelocity().getY().getValue(), 3.0e-13);
        Assert.assertEquals(z.getPartialDerivative(1), normalized.getVelocity().getZ().getValue(), 3.0e-13);
        Assert.assertEquals(x.getPartialDerivative(2), normalized.getAcceleration().getX().getValue(), 6.0e-10);
        Assert.assertEquals(y.getPartialDerivative(2), normalized.getAcceleration().getY().getValue(), 6.0e-10);
        Assert.assertEquals(z.getPartialDerivative(2), normalized.getAcceleration().getZ().getValue(), 6.0e-10);
    }
}
Also used : UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) FieldDerivativeStructure(org.hipparchus.analysis.differentiation.FieldDerivativeStructure) DSFactory(org.hipparchus.analysis.differentiation.DSFactory) Well19937a(org.hipparchus.random.Well19937a) RandomGenerator(org.hipparchus.random.RandomGenerator) FiniteDifferencesDifferentiator(org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator) Test(org.junit.Test)

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