Search in sources :

Example 41 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project Orekit by CS-SI.

the class Orbit method createInverseJacobian.

/**
 * Create an inverse Jacobian.
 * @param type type of the position angle to use
 * @return inverse Jacobian
 */
private double[][] createInverseJacobian(final PositionAngle type) {
    // get the direct Jacobian
    final double[][] directJacobian = new double[6][6];
    getJacobianWrtCartesian(type, directJacobian);
    // invert the direct Jacobian
    final RealMatrix matrix = MatrixUtils.createRealMatrix(directJacobian);
    final DecompositionSolver solver = new QRDecomposition(matrix).getSolver();
    return solver.getInverse().getData();
}
Also used : QRDecomposition(org.hipparchus.linear.QRDecomposition) RealMatrix(org.hipparchus.linear.RealMatrix) DecompositionSolver(org.hipparchus.linear.DecompositionSolver)

Example 42 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project symja_android_library by axkr.

the class ComplexFormFactory method convertList.

public void convertList(final StringBuilder buf, final IAST list) {
    if (list instanceof ASTRealVector) {
        RealVector vector = ((ASTRealVector) list).getRealVector();
        buf.append('{');
        int size = vector.getDimension();
        for (int i = 0; i < size; i++) {
            convertDouble(buf, vector.getEntry(i));
            if (i < size - 1) {
                buf.append(",");
            }
        }
        buf.append('}');
        return;
    }
    if (list instanceof ASTRealMatrix) {
        RealMatrix matrix = ((ASTRealMatrix) list).getRealMatrix();
        buf.append('{');
        int rows = matrix.getRowDimension();
        int cols = matrix.getColumnDimension();
        for (int i = 0; i < rows; i++) {
            if (i != 0) {
                buf.append(" ");
            }
            buf.append("{");
            for (int j = 0; j < cols; j++) {
                convertDouble(buf, matrix.getEntry(i, j));
                if (j < cols - 1) {
                    buf.append(",");
                }
            }
            buf.append('}');
            if (i < rows - 1) {
                buf.append(",");
                buf.append('\n');
            }
        }
        buf.append('}');
        return;
    }
    if (list.isEvalFlagOn(IAST.IS_MATRIX)) {
        if (!fEmpty) {
            newLine(buf);
        }
    }
    append(buf, "{");
    final int listSize = list.size();
    if (listSize > 1) {
        convertInternal(buf, list.arg1());
    }
    for (int i = 2; i < listSize; i++) {
        append(buf, ",");
        if (list.isEvalFlagOn(IAST.IS_MATRIX)) {
            newLine(buf);
            append(buf, ' ');
        }
        convertInternal(buf, list.get(i));
    }
    append(buf, "}");
}
Also used : ASTRealMatrix(org.matheclipse.core.expression.ASTRealMatrix) RealMatrix(org.hipparchus.linear.RealMatrix) ASTRealMatrix(org.matheclipse.core.expression.ASTRealMatrix) ASTRealVector(org.matheclipse.core.expression.ASTRealVector) RealVector(org.hipparchus.linear.RealVector) ASTRealVector(org.matheclipse.core.expression.ASTRealVector)

Example 43 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project symja_android_library by axkr.

the class AbstractMatrix1Expr method numericEval.

@Override
public IExpr numericEval(final IAST ast, final EvalEngine engine) {
    RealMatrix matrix;
    IExpr arg1 = ast.arg1();
    int[] dim = checkMatrixDimensions(arg1);
    if (dim != null) {
        try {
            if (engine.isArbitraryMode()) {
                FieldMatrix<IExpr> fieldMatrix = Convert.list2Matrix(arg1);
                if (fieldMatrix != null) {
                    Predicate<IExpr> zeroChecker = optionZeroTest(ast, 2, engine);
                    return matrixEval(fieldMatrix, zeroChecker);
                }
                return F.NIL;
            }
            matrix = arg1.toRealMatrix();
            if (matrix != null) {
                return realMatrixEval(matrix);
            } else {
                FieldMatrix<IExpr> fieldMatrix = Convert.list2Matrix(arg1);
                if (fieldMatrix != null) {
                    Predicate<IExpr> zeroChecker = optionZeroTest(ast, 2, engine);
                    return matrixEval(fieldMatrix, zeroChecker);
                }
            }
        } catch (LimitException le) {
            throw le;
        } catch (final MathRuntimeException mre) {
            // org.hipparchus.exception.MathIllegalArgumentException: inconsistent dimensions: 0 != 3
            LOGGER.log(engine.getLogLevel(), ast.topHead(), mre);
        } catch (final RuntimeException e) {
            LOGGER.debug("AbstractMatrix1Expr.numericEval() failed", e);
        }
    }
    return F.NIL;
}
Also used : MathRuntimeException(org.hipparchus.exception.MathRuntimeException) MathRuntimeException(org.hipparchus.exception.MathRuntimeException) RealMatrix(org.hipparchus.linear.RealMatrix) IExpr(org.matheclipse.core.interfaces.IExpr) LimitException(org.matheclipse.core.eval.exception.LimitException)

Example 44 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project symja_android_library by axkr.

the class RootsFunctions method findRoots.

/**
 * Given a set of polynomial coefficients, compute the roots of the polynomial. Depending on the
 * polynomial being considered the roots may contain complex number. When complex numbers are
 * present they will come in pairs of complex conjugates.
 *
 * @param coefficients coefficients of the polynomial.
 * @return the roots of the polynomial
 * @throws RuntimeException
 */
private static IAST findRoots(double... coefficients) {
    int N = coefficients.length - 1;
    // Construct the companion matrix
    RealMatrix c = new Array2DRowRealMatrix(N, N);
    double a = coefficients[N];
    for (int i = 0; i < N; i++) {
        c.setEntry(i, N - 1, -coefficients[i] / a);
    }
    for (int i = 1; i < N; i++) {
        c.setEntry(i, i - 1, 1);
    }
    EigenDecomposition ed = new EigenDecomposition(c);
    double[] realValues = ed.getRealEigenvalues();
    double[] imagValues = ed.getImagEigenvalues();
    IASTAppendable roots = F.ListAlloc(N);
    return roots.appendArgs(0, N, i -> F.chopExpr(F.complexNum(realValues[i], imagValues[i]), Config.DEFAULT_ROOTS_CHOP_DELTA));
// for (int i = 0; i < N; i++) {
// roots.append(F.chopExpr(F.complexNum(realValues[i], imagValues[i]),
// Config.DEFAULT_ROOTS_CHOP_DELTA));
// }
// return roots;
}
Also used : EigenDecomposition(org.hipparchus.linear.EigenDecomposition) RealMatrix(org.hipparchus.linear.RealMatrix) Array2DRowRealMatrix(org.hipparchus.linear.Array2DRowRealMatrix) Array2DRowRealMatrix(org.hipparchus.linear.Array2DRowRealMatrix) IASTAppendable(org.matheclipse.core.interfaces.IASTAppendable)

Aggregations

RealMatrix (org.hipparchus.linear.RealMatrix)44 Test (org.junit.Test)17 Orbit (org.orekit.orbits.Orbit)14 Propagator (org.orekit.propagation.Propagator)14 NumericalPropagatorBuilder (org.orekit.propagation.conversion.NumericalPropagatorBuilder)13 ParameterDriversList (org.orekit.utils.ParameterDriversList)13 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)12 Array2DRowRealMatrix (org.hipparchus.linear.Array2DRowRealMatrix)12 Context (org.orekit.estimation.Context)12 ObservedMeasurement (org.orekit.estimation.measurements.ObservedMeasurement)12 OrbitType (org.orekit.orbits.OrbitType)10 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)10 ParameterDriver (org.orekit.utils.ParameterDriver)10 RealVector (org.hipparchus.linear.RealVector)8 PositionAngle (org.orekit.orbits.PositionAngle)8 ArrayList (java.util.ArrayList)7 GeodeticPoint (org.orekit.bodies.GeodeticPoint)6 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)5 OrekitException (org.orekit.errors.OrekitException)5 DelegatingDriver (org.orekit.utils.ParameterDriversList.DelegatingDriver)5