1

I'm currently using the ojAlgo v45.1.0. I have a question regarding how to get the trace and the sum of a matrix. As I store a matrix in the class PrimitiveDenseStore, it is not feasible to see methods to compute the trace and the sum of the matrix. So, does anyone know how to get the trace and the sum of a matrix in the class PrimitiveDenseStore? Thank you in advance!

nhavt
  • 349
  • 2
  • 10
  • Do you know how to calculate the matrix rank using any other library (or pen and paper)? – apete Jun 11 '18 at 08:26
  • Hi Apete, thank you for your response. Yes, I do know how to get the rank, the trace, or the sum of a matrix using EJML. For example, with EJML, when I wish to compute the rank, the trace or the sum of a matrix, I can simply call A.trace(), A.svd(true).rank(), or A.elementSum(), where A is variable in the class SimpleMatrix (https://ejml.org/wiki/index.php?title=Matlab_to_EJML). I was wondering whether I can do the same if I use the class PrimitiveDenseStore in your package. Thank you in advance! – nhavt Jun 11 '18 at 09:49

1 Answers1

1

In ojAlgo BasicMatrix is what best corresponds to EJML's SimpleMatrix (I guess).

With PrimitiveDenseStore things are not done for you, but you can do a lot more. Here's one way to calculate the trace:

double trace = denseStore.aggregateDiagonal(SUM);

There is an interface MatrixDecomposition.RankRevealing that a number of matrix decompositions implement. To instantiate an SVD:

SingularValue<Double> svd = SingularValue.make(denseStore);
svd.decompose(denseStore);
svd.getRank();
apete
  • 1,250
  • 1
  • 10
  • 16
  • Hi Apete, thank you very much for your swift reply. Yes, your code examples are exactly what I need. Also, I was wondering whether there is an online documentation regarding the code examples so that I can read. For instance, an online documentation links MATLAB and ojalgo, which is similar to the following online documentation (https://ejml.org/wiki/index.php?title=Matlab_to_EJML). That would be very useful. Thank you in advance! – nhavt Jun 12 '18 at 07:55
  • https://github.com/optimatika/ojAlgo/wiki There is no specific "ojAlgo for MATLAB users" page. – apete Jun 12 '18 at 08:23