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?