commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sujit Pal (JIRA)" <>
Subject [jira] Created: (MATH-232) Would like to have RealMatrix.getFrobeniusNorm()
Date Wed, 03 Dec 2008 21:35:44 GMT
Would like to have RealMatrix.getFrobeniusNorm()

                 Key: MATH-232
             Project: Commons Math
          Issue Type: New Feature
         Environment: Any
            Reporter: Sujit Pal

I have been converting over some of my code that used Jama to use commons-math. One thing
I would like to have is Matrix.normF() which returns the Frobenius norm (ie the square root
of the sum of squares of all the elements).

I have gotten around this by implementing this as a utility method, like so:

   * Return the square root of the sum of squares of all elements in
   * the matrix. In Jama, it is Matrix.normF().
   * @param matrix a RealMatrix.
   * @return the Frobenius norm.
  public static double getFrobeniusNorm(RealMatrix matrix) {
    double frobeniusNorm = 0.0D;
    for (int row = 0; row < matrix.getRowDimension(); row++) {
      for (int col = 0; col < matrix.getColumnDimension(); col++) {
         frobeniusNorm += Math.pow(matrix.getEntry(row, col), 2);
    return Math.sqrt(frobeniusNorm);

It would be nice if RealMatrix mandated a method getFrobeniusNorm() like getNorm(), that way
this method is available from within a RealMatrix.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message