为什么Jama矩阵的内部尺寸在第一次迭代中一致,但后来却不一致? [英] Why does the Jama matrix inner dimension agree in the first iteration, but later it does not?

查看:90
本文介绍了为什么Jama矩阵的内部尺寸在第一次迭代中一致,但后来却不一致?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Jama矩阵在我的代码中定义:

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

以下是我的代码段:

private Matrix getP() {
        P= (I.minus(K.times(H))).times(Q);
        Log.d("csv", "P is calculated");
        return P;
    }

在运行代码时,它会在第一次迭代时起作用,即P is calculated会打印在Logcat上.但是,它仅发生一次,并且应用程序被停止.错误如下:

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.

如果Matrix内部维是错误,那么它如何在第一次迭代中运行?我在链接.但是,我不知道解决方案.手动检查方程式时,矩阵尺寸匹配. 我的方法有什么问题吗?

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??

谢谢.

推荐答案

您介意显示您如何呼叫getP吗?无论我单击fab按钮多少次,以下内容均有效.

Do you mind showing how you are calling getP? The following works no matter how many times I click on the fab button.

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
    }
}

getP返回时,您将结果存储在何处?您可能会覆盖其中一个矩阵吗?

When getP returns where are you storing the results? Are you possibly overwriting one of the matrices?

更新

如果您的情况是使变量成为最终变量不是您的选择,那么您可以记录每个矩阵的维,然后调试发生变化的维.

If your situation is such that making the variables final is not an option for you, then you can log each matrix's dimension and then debug the one that changes.

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
}

这篇关于为什么Jama矩阵的内部尺寸在第一次迭代中一致,但后来却不一致?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆