Jama Matrices are defined in my code (Matrix computation class) as follows:
private Matrix A;
private Matrix B;
private Matrix C;
The matrix A is initialized as follows:
A = new Matrix(2,2);
A.set(0,0,1.5);
A.set(0,1,0.0);
A.set(1,0,0.0);
A.set(1,1,1.5);
Matrix B is a 2*2 matrix, initialized as an identity matrix and is updated every second by the next matrix of the same size from the MainActivity class.
Matrix C is initialized and computed as follows:
if(C!=null)
C = A.plus(C.times(B));
else {
C = new Matrix(2,2);
C.set(0,0,1);
C.set(0,1,0.0);
C.set(1,0,0.0);
C.set(1,1,1);
Here, the Matrix computation class is called by the MainActivity class every second and matrix B is updated accordingly. However, the code runs well for only the first iteration and throws an error in later as follows:
java.lang.IllegalArgumentException: Matrix inner dimensions must agree.
After some digging, I found that it is caused due to matrix overwriting (Matrix B and C). The matrices in my code cannot be static or final. Is there any way to use the Jama matrix when the matrices are not static? Are there any alternatives to Jama in the android studio for Matrix operation?
Looking at the source code provided with JAMA, the IllegalArgumentException is thrown at that place:
So appearently
C.times(B)fails, which means thatCandBdimensions do not agree. As we can also see from the line below,C = new Matrix(2,2)does have 2x2 size, which means thatBmust have a wrong size.I do not understand what you mean with "matrix overwriting"?
C = A.plus(C.times(B))does allocate a new instance ofMatrixinternally. This has nothing to do withstaticorfinal.Please provide a complete, minimal example. There are many parts missing, like the place where B is initialized.