use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class FundamentalNutationArgumentsTest method testDotField.
@Test
public void testDotField() throws OrekitException {
final IERSConventions conventions = IERSConventions.IERS_2010;
final TimeScale ut1 = TimeScalesFactory.getUT1(conventions, false);
final FundamentalNutationArguments fna = conventions.getNutationArguments(ut1);
final FieldAbsoluteDate<Decimal64> t0 = new FieldAbsoluteDate<>(Decimal64Field.getInstance(), 2002, 4, 7, 12, 34, 22.5, TimeScalesFactory.getUTC());
final UnivariateDifferentiableFunction gamma = differentiate(fna, t0, b -> b.getGamma());
final UnivariateDifferentiableFunction l = differentiate(fna, t0, b -> b.getL());
final UnivariateDifferentiableFunction lPrime = differentiate(fna, t0, b -> b.getLPrime());
final UnivariateDifferentiableFunction f = differentiate(fna, t0, b -> b.getF());
final UnivariateDifferentiableFunction d = differentiate(fna, t0, b -> b.getD());
final UnivariateDifferentiableFunction lMe = differentiate(fna, t0, b -> b.getLMe());
final UnivariateDifferentiableFunction lVe = differentiate(fna, t0, b -> b.getLVe());
final UnivariateDifferentiableFunction lE = differentiate(fna, t0, b -> b.getLE());
final UnivariateDifferentiableFunction lMa = differentiate(fna, t0, b -> b.getLMa());
final UnivariateDifferentiableFunction lJu = differentiate(fna, t0, b -> b.getLJu());
final UnivariateDifferentiableFunction lSa = differentiate(fna, t0, b -> b.getLSa());
final UnivariateDifferentiableFunction lUr = differentiate(fna, t0, b -> b.getLUr());
final UnivariateDifferentiableFunction lNe = differentiate(fna, t0, b -> b.getLNe());
final UnivariateDifferentiableFunction pa = differentiate(fna, t0, b -> b.getPa());
final DSFactory factory = new DSFactory(1, 1);
double maxErrorGamma = 0;
double maxErrorL = 0;
double maxErrorLPrime = 0;
double maxErrorF = 0;
double maxErrorD = 0;
double maxErrorLMe = 0;
double maxErrorLVe = 0;
double maxErrorLE = 0;
double maxErrorLMa = 0;
double maxErrorLJu = 0;
double maxErrorLSa = 0;
double maxErrorLUr = 0;
double maxErrorLNe = 0;
double maxErrorPa = 0;
for (double dt = 0; dt < Constants.JULIAN_DAY; dt += 60.0) {
FieldBodiesElements<Decimal64> be = fna.evaluateAll(t0.shiftedBy(dt));
DerivativeStructure dtDS = factory.variable(0, dt);
maxErrorGamma = FastMath.max(maxErrorGamma, FastMath.abs(gamma.value(dtDS).getPartialDerivative(1) - be.getGammaDot().getReal()));
maxErrorL = FastMath.max(maxErrorL, FastMath.abs(l.value(dtDS).getPartialDerivative(1) - be.getLDot().getReal()));
maxErrorLPrime = FastMath.max(maxErrorLPrime, FastMath.abs(lPrime.value(dtDS).getPartialDerivative(1) - be.getLPrimeDot().getReal()));
maxErrorF = FastMath.max(maxErrorF, FastMath.abs(f.value(dtDS).getPartialDerivative(1) - be.getFDot().getReal()));
maxErrorD = FastMath.max(maxErrorD, FastMath.abs(d.value(dtDS).getPartialDerivative(1) - be.getDDot().getReal()));
maxErrorLMe = FastMath.max(maxErrorLMe, FastMath.abs(lMe.value(dtDS).getPartialDerivative(1) - be.getLMeDot().getReal()));
maxErrorLVe = FastMath.max(maxErrorLVe, FastMath.abs(lVe.value(dtDS).getPartialDerivative(1) - be.getLVeDot().getReal()));
maxErrorLE = FastMath.max(maxErrorLE, FastMath.abs(lE.value(dtDS).getPartialDerivative(1) - be.getLEDot().getReal()));
maxErrorLMa = FastMath.max(maxErrorLMa, FastMath.abs(lMa.value(dtDS).getPartialDerivative(1) - be.getLMaDot().getReal()));
maxErrorLJu = FastMath.max(maxErrorLJu, FastMath.abs(lJu.value(dtDS).getPartialDerivative(1) - be.getLJuDot().getReal()));
maxErrorLSa = FastMath.max(maxErrorLSa, FastMath.abs(lSa.value(dtDS).getPartialDerivative(1) - be.getLSaDot().getReal()));
maxErrorLUr = FastMath.max(maxErrorLUr, FastMath.abs(lUr.value(dtDS).getPartialDerivative(1) - be.getLUrDot().getReal()));
maxErrorLNe = FastMath.max(maxErrorLNe, FastMath.abs(lNe.value(dtDS).getPartialDerivative(1) - be.getLNeDot().getReal()));
maxErrorPa = FastMath.max(maxErrorPa, FastMath.abs(pa.value(dtDS).getPartialDerivative(1) - be.getPaDot().getReal()));
}
Assert.assertEquals(0, maxErrorGamma, 8.0e-13);
Assert.assertEquals(0, maxErrorL, 1.0e-14);
Assert.assertEquals(0, maxErrorLPrime, 6.0e-16);
Assert.assertEquals(0, maxErrorF, 6.0e-15);
Assert.assertEquals(0, maxErrorD, 6.0e-15);
Assert.assertEquals(0, maxErrorLMe, 2.0e-15);
Assert.assertEquals(0, maxErrorLVe, 5.0e-16);
Assert.assertEquals(0, maxErrorLE, 3.0e-16);
Assert.assertEquals(0, maxErrorLMa, 4.0e-16);
Assert.assertEquals(0, maxErrorLJu, 3.0e-17);
Assert.assertEquals(0, maxErrorLSa, 4.0e-17);
Assert.assertEquals(0, maxErrorLUr, 1.0e-16);
Assert.assertEquals(0, maxErrorLNe, 8.0e-17);
Assert.assertEquals(0, maxErrorPa, 3.0e-20);
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class FundamentalNutationArgumentsTest method testDotDouble.
@Test
public void testDotDouble() throws OrekitException {
final IERSConventions conventions = IERSConventions.IERS_2010;
final TimeScale ut1 = TimeScalesFactory.getUT1(conventions, false);
final FundamentalNutationArguments fna = conventions.getNutationArguments(ut1);
final AbsoluteDate t0 = new AbsoluteDate(2002, 4, 7, 12, 34, 22.5, TimeScalesFactory.getUTC());
final UnivariateDifferentiableFunction gamma = differentiate(fna, t0, b -> b.getGamma());
final UnivariateDifferentiableFunction l = differentiate(fna, t0, b -> b.getL());
final UnivariateDifferentiableFunction lPrime = differentiate(fna, t0, b -> b.getLPrime());
final UnivariateDifferentiableFunction f = differentiate(fna, t0, b -> b.getF());
final UnivariateDifferentiableFunction d = differentiate(fna, t0, b -> b.getD());
final UnivariateDifferentiableFunction lMe = differentiate(fna, t0, b -> b.getLMe());
final UnivariateDifferentiableFunction lVe = differentiate(fna, t0, b -> b.getLVe());
final UnivariateDifferentiableFunction lE = differentiate(fna, t0, b -> b.getLE());
final UnivariateDifferentiableFunction lMa = differentiate(fna, t0, b -> b.getLMa());
final UnivariateDifferentiableFunction lJu = differentiate(fna, t0, b -> b.getLJu());
final UnivariateDifferentiableFunction lSa = differentiate(fna, t0, b -> b.getLSa());
final UnivariateDifferentiableFunction lUr = differentiate(fna, t0, b -> b.getLUr());
final UnivariateDifferentiableFunction lNe = differentiate(fna, t0, b -> b.getLNe());
final UnivariateDifferentiableFunction pa = differentiate(fna, t0, b -> b.getPa());
final DSFactory factory = new DSFactory(1, 1);
double maxErrorGamma = 0;
double maxErrorL = 0;
double maxErrorLPrime = 0;
double maxErrorF = 0;
double maxErrorD = 0;
double maxErrorLMe = 0;
double maxErrorLVe = 0;
double maxErrorLE = 0;
double maxErrorLMa = 0;
double maxErrorLJu = 0;
double maxErrorLSa = 0;
double maxErrorLUr = 0;
double maxErrorLNe = 0;
double maxErrorPa = 0;
for (double dt = 0; dt < Constants.JULIAN_DAY; dt += 60.0) {
BodiesElements be = fna.evaluateAll(t0.shiftedBy(dt));
DerivativeStructure dtDS = factory.variable(0, dt);
maxErrorGamma = FastMath.max(maxErrorGamma, FastMath.abs(gamma.value(dtDS).getPartialDerivative(1) - be.getGammaDot()));
maxErrorL = FastMath.max(maxErrorL, FastMath.abs(l.value(dtDS).getPartialDerivative(1) - be.getLDot()));
maxErrorLPrime = FastMath.max(maxErrorLPrime, FastMath.abs(lPrime.value(dtDS).getPartialDerivative(1) - be.getLPrimeDot()));
maxErrorF = FastMath.max(maxErrorF, FastMath.abs(f.value(dtDS).getPartialDerivative(1) - be.getFDot()));
maxErrorD = FastMath.max(maxErrorD, FastMath.abs(d.value(dtDS).getPartialDerivative(1) - be.getDDot()));
maxErrorLMe = FastMath.max(maxErrorLMe, FastMath.abs(lMe.value(dtDS).getPartialDerivative(1) - be.getLMeDot()));
maxErrorLVe = FastMath.max(maxErrorLVe, FastMath.abs(lVe.value(dtDS).getPartialDerivative(1) - be.getLVeDot()));
maxErrorLE = FastMath.max(maxErrorLE, FastMath.abs(lE.value(dtDS).getPartialDerivative(1) - be.getLEDot()));
maxErrorLMa = FastMath.max(maxErrorLMa, FastMath.abs(lMa.value(dtDS).getPartialDerivative(1) - be.getLMaDot()));
maxErrorLJu = FastMath.max(maxErrorLJu, FastMath.abs(lJu.value(dtDS).getPartialDerivative(1) - be.getLJuDot()));
maxErrorLSa = FastMath.max(maxErrorLSa, FastMath.abs(lSa.value(dtDS).getPartialDerivative(1) - be.getLSaDot()));
maxErrorLUr = FastMath.max(maxErrorLUr, FastMath.abs(lUr.value(dtDS).getPartialDerivative(1) - be.getLUrDot()));
maxErrorLNe = FastMath.max(maxErrorLNe, FastMath.abs(lNe.value(dtDS).getPartialDerivative(1) - be.getLNeDot()));
maxErrorPa = FastMath.max(maxErrorPa, FastMath.abs(pa.value(dtDS).getPartialDerivative(1) - be.getPaDot()));
}
Assert.assertEquals(0, maxErrorGamma, 8.0e-13);
Assert.assertEquals(0, maxErrorL, 1.0e-14);
Assert.assertEquals(0, maxErrorLPrime, 6.0e-16);
Assert.assertEquals(0, maxErrorF, 6.0e-15);
Assert.assertEquals(0, maxErrorD, 6.0e-15);
Assert.assertEquals(0, maxErrorLMe, 2.0e-15);
Assert.assertEquals(0, maxErrorLVe, 5.0e-16);
Assert.assertEquals(0, maxErrorLE, 3.0e-16);
Assert.assertEquals(0, maxErrorLMa, 4.0e-16);
Assert.assertEquals(0, maxErrorLJu, 3.0e-17);
Assert.assertEquals(0, maxErrorLSa, 4.0e-17);
Assert.assertEquals(0, maxErrorLUr, 1.0e-16);
Assert.assertEquals(0, maxErrorLNe, 8.0e-17);
Assert.assertEquals(0, maxErrorPa, 3.0e-20);
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction 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();
}
}
};
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class PredefinedIAUPolesTest method testDerivatives.
@Test
public void testDerivatives() {
final DSFactory factory = new DSFactory(1, 1);
final AbsoluteDate ref = AbsoluteDate.J2000_EPOCH;
final FieldAbsoluteDate<DerivativeStructure> refDS = new FieldAbsoluteDate<>(factory.getDerivativeField(), ref);
FiniteDifferencesDifferentiator differentiator = new FiniteDifferencesDifferentiator(8, 60.0);
for (final IAUPole iaupole : PredefinedIAUPoles.values()) {
UnivariateDifferentiableVectorFunction dPole = differentiator.differentiate(new UnivariateVectorFunction() {
@Override
public double[] value(double t) {
return iaupole.getPole(ref.shiftedBy(t)).toArray();
}
});
UnivariateDifferentiableFunction dMeridian = differentiator.differentiate(new UnivariateFunction() {
@Override
public double value(double t) {
return iaupole.getPrimeMeridianAngle(ref.shiftedBy(t));
}
});
for (double dt = 0; dt < Constants.JULIAN_YEAR; dt += 3600) {
final DerivativeStructure dtDS = factory.variable(0, dt);
final DerivativeStructure[] refPole = dPole.value(dtDS);
final DerivativeStructure[] fieldPole = iaupole.getPole(refDS.shiftedBy(dtDS)).toArray();
for (int i = 0; i < 3; ++i) {
Assert.assertEquals(refPole[i].getValue(), fieldPole[i].getValue(), 2.0e-15);
Assert.assertEquals(refPole[i].getPartialDerivative(1), fieldPole[i].getPartialDerivative(1), 4.0e-17);
}
final DerivativeStructure refMeridian = dMeridian.value(dtDS);
final DerivativeStructure fieldMeridian = iaupole.getPrimeMeridianAngle(refDS.shiftedBy(dtDS));
Assert.assertEquals(refMeridian.getValue(), fieldMeridian.getValue(), 4.0e-12);
Assert.assertEquals(refMeridian.getPartialDerivative(1), fieldMeridian.getPartialDerivative(1), 9.0e-14);
}
}
}
use of org.hipparchus.analysis.differentiation.UnivariateDifferentiableFunction in project Orekit by CS-SI.
the class EquinoctialOrbitTest method differentiate.
private <S extends Function<EquinoctialOrbit, 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 EquinoctialOrbit(pv.shiftedBy(dt), frame, mu));
}
});
return diff.value(factory.variable(0, 0.0)).getPartialDerivative(1);
}
Aggregations