You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Kosumo <ma...@gmail.com> on 2010/06/07 12:11:37 UTC

[math] About RealMatrix

Dear all,

I got confused with the "equals" method applied to OpenMapRealMatrix
instance.
I have this following code:

RealMatrix raw = vectorGenerator.getMatrix();
RealMatrix test =
TestHelper.parseMatrixFromFile("resources/raw_matrix.txt");

both the raw and test matrices are the instance of OpenMapRealMatrix. The
test matrix is generated by reading the matrix value from a text file.
Both of them are intended to have the same value as follow:

0.0000  0.0000  1.0000  1.0000  0.0000  0.0000  0.0000  0.0000  0.0000
0.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000  0.0000  1.0000
0.0000  1.0000  0.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000
0.0000  1.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000  0.0000
0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000  1.0000
1.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000  0.0000  0.0000
1.0000  1.0000  1.0000  1.0000  1.0000  1.0000  1.0000  1.0000  1.0000
1.0000  0.0000  1.0000  1.0000  0.0000  0.0000  0.0000  0.0000  0.0000
1.0000  0.0000  1.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000
0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000  1.0000
0.0000  0.0000  0.0000  0.0000  0.0000  2.0000  0.0000  0.0000  1.0000
1.0000  0.0000  1.0000  0.0000  0.0000  0.0000  0.0000  1.0000  0.0000
0.0000  0.0000  0.0000  1.0000  1.0000  0.0000  0.0000  0.0000  0.0000

I want to test if they really have the same value. I tried to use "equals"
method, Eclipse indicates that 'equals' is method from Object class.
I suppose it will generate false since both matrices are not the same
object. However when I execute this statement:

              raw.equals(test)

it generate "true".

In other case where the value of both matrix:
0.0000  0.0000  0.1306  0.1633  0.0000  0.0000  0.0000  0.0000  0.0000
0.0000  0.0000  0.0000  0.0000  0.0000  0.1306  0.0000  0.0000  0.1306
0.0000  0.2177  0.0000  0.0000  0.0000  0.0000  0.0000  0.2177  0.0000
0.0000  0.2177  0.0000  0.0000  0.0000  0.0000  0.1633  0.0000  0.0000
0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.1633  0.0000  0.1306
0.1306  0.0000  0.0000  0.0000  0.0000  0.1306  0.0000  0.0000  0.0000
0.0000  0.0171  0.0102  0.0128  0.0256  0.0102  0.0128  0.0171  0.0102
0.0954  0.0000  0.0954  0.1193  0.0000  0.0000  0.0000  0.0000  0.0000
0.1306  0.0000  0.1306  0.0000  0.0000  0.0000  0.0000  0.0000  0.0000
0.0000  0.0000  0.0000  0.0000  0.0000  0.0000  0.1633  0.0000  0.1306
0.0000  0.0000  0.0000  0.0000  0.0000  0.2613  0.0000  0.0000  0.1306
0.0954  0.0000  0.0954  0.0000  0.0000  0.0000  0.0000  0.1590  0.0000
0.0000  0.0000  0.0000  0.1633  0.3266  0.0000  0.0000  0.0000  0.0000

the above statement give me "false" value.

Can anyone explain about this? I tried to look at the API. I found
that OpenMapRealMatrix is subclass of AbstractRealMatrix.
AbstractRealMatrix has an 'equals' method, but I can't access it since
Eclipse still indicate that the 'equals' method is the one from Object
class.
How can I use 'equals' method from AbstractRealMatrix? Is it possible to use
it for comparing value from two matrices?
Thanks in advance,

Kosumo