use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class PVCoordinatesTest method testNormalize.
@Test
public void testNormalize() {
DSFactory factory = new DSFactory(1, 2);
RandomGenerator generator = new Well19937a(0xb2011ffd25412067l);
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(5, 1.0e-3);
for (int i = 0; i < 200; ++i) {
final PVCoordinates 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();
}
}).value(factory.variable(0, 0.0));
DerivativeStructure y = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return pv.shiftedBy(t).getPosition().normalize().getY();
}
}).value(factory.variable(0, 0.0));
DerivativeStructure z = differentiator.differentiate(new UnivariateFunction() {
public double value(double t) {
return pv.shiftedBy(t).getPosition().normalize().getZ();
}
}).value(factory.variable(0, 0.0));
PVCoordinates normalized = pv.normalize();
Assert.assertEquals(x.getValue(), normalized.getPosition().getX(), 1.0e-16);
Assert.assertEquals(y.getValue(), normalized.getPosition().getY(), 1.0e-16);
Assert.assertEquals(z.getValue(), normalized.getPosition().getZ(), 1.0e-16);
Assert.assertEquals(x.getPartialDerivative(1), normalized.getVelocity().getX(), 3.0e-13);
Assert.assertEquals(y.getPartialDerivative(1), normalized.getVelocity().getY(), 3.0e-13);
Assert.assertEquals(z.getPartialDerivative(1), normalized.getVelocity().getZ(), 3.0e-13);
Assert.assertEquals(x.getPartialDerivative(2), normalized.getAcceleration().getX(), 6.0e-10);
Assert.assertEquals(y.getPartialDerivative(2), normalized.getAcceleration().getY(), 6.0e-10);
Assert.assertEquals(z.getPartialDerivative(2), normalized.getAcceleration().getZ(), 6.0e-10);
}
}
use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class IERSConventionsTest method checkGMSTRate.
private void checkGMSTRate(final TimeScalarFunction gmst, final TimeScalarFunction gmstRate, final AbsoluteDate date, final double span, final double sampleStep, final double h, final double tolerance) throws OrekitException {
UnivariateDifferentiableFunction differentiated = new FiniteDifferencesDifferentiator(4, h).differentiate(new UnivariateFunction() {
@Override
public double value(final double dt) {
return gmst.value(date.shiftedBy(dt));
}
});
DSFactory factory = new DSFactory(1, 1);
double maxRateError = 0;
for (double dt = 0; dt < span; dt += sampleStep) {
double rateRef = differentiated.value(factory.variable(0, dt)).getPartialDerivative(1);
double rate = gmstRate.value(date.shiftedBy(dt));
maxRateError = FastMath.max(maxRateError, FastMath.abs(rateRef - rate));
}
Assert.assertEquals(0, maxRateError, tolerance);
}
use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class CartesianOrbitTest method differentiate.
private <S extends Function<CartesianOrbit, Double>> double differentiate(TimeStampedPVCoordinates 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 CartesianOrbit(pv.shiftedBy(dt), frame, mu));
}
});
return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class CircularOrbitTest method differentiate.
private <S extends Function<CircularOrbit, Double>> double differentiate(TimeStampedPVCoordinates 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 CircularOrbit(pv.shiftedBy(dt), frame, mu));
}
});
return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
use of org.hipparchus.analysis.differentiation.FiniteDifferencesDifferentiator in project Orekit by CS-SI.
the class FieldCircularOrbitTest method differentiate.
private <T extends RealFieldElement<T>, S extends Function<FieldCircularOrbit<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 FieldCircularOrbit<>(pv.shiftedBy(dt), frame, mu)).getReal();
}
});
return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Aggregations