commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kosumo <mas.kos...@gmail.com>
Subject [math] About RealMatrix
Date Mon, 07 Jun 2010 10:11:37 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message