san*_*edi 5 android matrix jama matrix-multiplication android-studio
Following Jama
Matrices are defined in my code:
P: 3*3 Matrix
I: 3*3 identity Matrix
K: 3*2 Matrix
H: 2*3 Matrix
Q: 3*3 Matrix
Run Code Online (Sandbox Code Playgroud)
Following is my code snippet:
private Matrix getP() {
P= (I.minus(K.times(H))).times(Q);
Log.d("csv", "P is calculated");
return P;
}
Run Code Online (Sandbox Code Playgroud)
While running the code, at first iteration it works, i.e, P is calculated
is printed at the Logcat. However, it happens only once and the application gets stopped. Following is the error:
java.lang.IllegalArgumentException: Matrix inner dimensions must agree.
Run Code Online (Sandbox Code Playgroud)
If the Matrix inner dimension was the error, how come it runs for the first iteration? I obtained some information about the inner dimension at this link. However, I could not figure out the solution. When the equation is manually checked, the matrix dimension matches. Anything wrong with my approach??
Thank you.
您介意显示您的通话方式getP
吗?无论我单击多少次,以下内容均有效fab
。
class MainActivity : AppCompatActivity() {
val I = Matrix.identity(3,3)
val K = Matrix(3,2,5.0)
val H = Matrix(2,3,7.0)
val Q = Matrix(3,3,8.0)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
fab.setOnClickListener { view ->
getP()
}
}
private fun getP():Matrix{
val P = (I.minus(K.times(H))).times(Q)
Log.d("MainActivity","P is calculated")
return P
}
}
Run Code Online (Sandbox Code Playgroud)
什么时候getP
退货,您将结果存储在哪里?您是否可能覆盖其中一个矩阵?
更新资料
如果您的情况是使变量成为最终变量不是您的选择,则可以记录每个矩阵的维,然后调试变化的维。
private fun getP():Matrix{
Log.d(TAG,"I dimension: ${I.rowDimension} x ${I.columnDimension}")
Log.d(TAG,"K dimension: ${K.rowDimension} x ${K.columnDimension}")
Log.d(TAG,"H dimension: ${H.rowDimension} x ${H.columnDimension}")
Log.d(TAG,"Q dimension: ${Q.rowDimension} x ${Q.columnDimension}")
val P = (I.minus(K.times(H))).times(Q)
Log.d(TAG,"P is calculated")
return P
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
126 次 |
最近记录: |