How To Overwrite/update A Jama Matrix In Android Studio Without Any Error?
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 M
Solution 1:
Looking at the source code provided with JAMA, the IllegalArgumentException is thrown at that place:
/** Linear algebraic matrix multiplication, A * B
@param B another matrix
@return Matrix product, A * B
@exception IllegalArgumentException Matrix inner dimensions must agree.
*/public Matrix times(Matrix B) {
if (B.m != n) {
thrownewIllegalArgumentException("Matrix inner dimensions must agree.");
}
MatrixX=newMatrix(m,B.n);
double[][] C = X.getArray();
double[] Bcolj = newdouble[n];
for (intj=0; j < B.n; j++) {
for (intk=0; k < n; k++) {
Bcolj[k] = B.A[k][j];
}
for (inti=0; i < m; i++) {
double[] Arowi = A[i];
doubles=0;
for (intk=0; k < n; k++) {
s += Arowi[k]*Bcolj[k];
}
C[i][j] = s;
}
}
return X;
}
So appearently C.times(B)
fails, which means that C
and B
dimensions do not agree. As we can also see from the line below, C = new Matrix(2,2)
does have 2x2 size, which means that B
must 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 of Matrix
internally. This has nothing to do with static
or final
.
Please provide a complete, minimal example. There are many parts missing, like the place where B is initialized.
Post a Comment for "How To Overwrite/update A Jama Matrix In Android Studio Without Any Error?"