1

これは少しばかげた質問かもしれませんし、私もこの問題に取り組むための最良の方法を誤解しているかもしれませんが、私が本質的にやりたいことは次のとおりです。

次の行列を乗算して、結果を-0.8にします。ただし、理想的にはJAMA関数を使用してこれを実行したいと思います。これまでのところ、私は次のことを行っていますが、もうすぐそこにいると思います。これは、私が立ち往生している最後のステップにすぎません。

// Create the two arrays (in reality I won't be creating these, the two 1D matrices
// will be the result of other calculations - I have just created them for this example)
double[] aArray = [0.2, -0.2];
double[] bArray = [0, 4];

// Create matrices out of the arrays
Matrix a = new Matrix( aArray, 1 );
Matrix b = new Matrix( bArray, 1 );

// Multiply matrix a by matrix b to get matrix c
Matrix c = a.times(b);

// Turn matrix c into a double
double x = // ... this is where I'm stuck

これに関するどんな助けも本当にありがたいです。前もって感謝します!

4

3 に答える 3

2

getを使用するという意味ですか?

double x = c.get(0, 0);

http://math.nist.gov/javanumerics/jama/doc/

于 2011-08-31T16:24:11.473 に答える
2

お探しのようですね

double x = c.get(0, 0);

また、行列には​​乗算に対して互換性のない次元があります。2番目のマトリックスは次のように構成する必要があるように見えます。

Matrix b = new Matrix( bArray, bArray.length );
于 2011-08-31T16:25:49.263 に答える
2

get()メソッドを使用するだけです。

double x = c.get(0,0);

ただし、2つの行ベクトルを乗算しようとしているため、IllegalArgumentExceptionが発生することに注意してください。ドキュメントから:times()

java.lang.IllegalArgumentException - Matrix inner dimensions must agree.

おそらく、2番目の配列を列ベクトルにしたいと思うでしょう。

于 2011-08-31T16:26:19.187 に答える