0

I am trying to have the least squares computed for an over determined system.

DenseMatrix64F D_dense = RandomMatrices.createRandom(dimension, 3 * dimension, -1, 1, r);

D1 = SimpleMatrix.wrap(D1).transpose().getMatrix();
LinearSolver<DenseMatrix64F> x2 = LinearSolverFactory.leastSquares(D1.numRows, D1.numCols);
x2.setA(D1);
DenseMatrix64F D_i = new DenseMatrix64F(D1.numRows, D1.numCols);
x2.invert(D_i);

But then I get the error

Exception in thread "main" java.lang.IllegalArgumentException: Unexpected dimensions for X: X rows = 9 expected = 3

What do I need to call that I can return the leastSquares for the Matrix D1?

Fabio Oesch
  • 143
  • 2
  • 11

1 Answers1

0

Looks like you're trying to invert a rectangular matrix. You can only invert a square matrix. That's also not the best way to solve. See the link below from the manual:

https://code.google.com/p/efficient-java-matrix-library/wiki/SolvingLinearSystems

lessthanoptimal
  • 2,722
  • 2
  • 23
  • 25