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();
}
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, "}");
}
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;
}
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;
}
Aggregations