Search code examples
javamatrixmatrix-multiplicationjama

How to multiply two 1D matrices using JAMA?


This may be a bit of a silly question and I might also have misunderstood the best way to approach this problem but what I essentially want to do is the following:

I want to multiply the following matrices together to get the result -0.8. However I would ideally like to do this using a JAMA function. So far I have the following and I think I'm almost there, it's just the last step I'm stuck on..

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

Any help on this would be really appreciated. Thanks in advance!


Solution

  • Do you mean using get?

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

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