Пример #1
0
 /**
  * Infinity norm
  *
  * @return maximum row sum.
  */
 public double normInf() {
   double f = 0;
   for (int i = 0; i < m; i++) {
     double s = 0;
     for (int j = 0; j < n; j++) {
       s += Math.abs(A[i][j]);
     }
     f = Math.max(f, s);
   }
   return f;
 }
Пример #2
0
 /**
  * Print the matrix to the output stream. Line the elements up in columns. Use the format object,
  * and right justify within columns of width characters. Note that is the matrix is to be read
  * back in, you probably will want to use a NumberFormat that is set to US Locale.
  *
  * @param output the output stream.
  * @param format A formatting object to format the matrix elements
  * @param width Column width.
  * @see java.text.DecimalFormat#setDecimalFormatSymbols
  */
 public void print(PrintWriter output, NumberFormat format, int width) {
   output.println(); // start on new line.
   for (int i = 0; i < m; i++) {
     for (int j = 0; j < n; j++) {
       String s = format.format(A[i][j]); // format the number
       int padding = Math.max(1, width - s.length()); // At _least_ 1 space
       for (int k = 0; k < padding; k++) output.print(' ');
       output.print(s);
     }
     output.println();
   }
   output.println(); // end with blank line.
 }