]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add the l1 (max sum of columns) and linfty (max sum of rows) matrix norms. These...
authorhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 26 Feb 1999 17:42:24 +0000 (17:42 +0000)
committerhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 26 Feb 1999 17:42:24 +0000 (17:42 +0000)
git-svn-id: https://svn.dealii.org/trunk@920 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/full_matrix.h
deal.II/lac/include/lac/full_matrix.templates.h
deal.II/lac/include/lac/sparse_matrix.h
deal.II/lac/include/lac/sparse_matrix.templates.h

index fa539f64451af5dbca49d2de492fec6c81f60961..9d2f480c14bb3e3f7a418d273dbc08bbd9087c5f 100644 (file)
@@ -333,6 +333,33 @@ class FullMatrix
                                      */
     template<typename number2>
     double matrix_scalar_product (const Vector<number2> &u, const Vector<number2> &v) const;
+
+                                    /**
+                                     * Return the l1-norm of the matrix, i.e.
+                                     * $|M|_1=max_{all columns j}\sum_{all 
+                                     * rows i} |M_ij|$,
+                                     * (max. sum of columns).
+                                     * This is the
+                                     * natural matrix norm that is compatible
+                                     * to the l1-norm for vectors, i.e.
+                                     * $|Mv|_1\leq |M|_1 |v|_1$.
+                                     * (cf. Rannacher Numerik0)
+                                     */
+    number l1_norm () const;
+
+                                    /**
+                                     * Return the linfty-norm of the
+                                     * matrix, i.e.
+                                     * $|M|_infty=max_{all rows i}\sum_{all 
+                                     * columns j} |M_ij|$,
+                                     * (max. sum of rows).
+                                     * This is the
+                                     * natural matrix norm that is compatible
+                                     * to the linfty-norm of vectors, i.e.
+                                     * $|Mv|_infty \leq |M|_infty |v|_infty$.
+                                     * (cf. Rannacher Numerik0)
+                                     */
+    number linfty_norm () const;
     
                                     /**
                                      * A=Inverse(A). Inversion of this by
index 0ca8d63e5648b492e4d9a074672b7bae512a34fa..2a153096f5ed3ff55e4489e8cad41f422cb704fd 100644 (file)
@@ -674,6 +674,41 @@ double FullMatrix<number>::matrix_scalar_product (const Vector<number2> &u, cons
 };
 
 
+template <typename number>
+number FullMatrix<number>::l1_norm () const
+{
+  number sum=0, max=0;
+  const unsigned int n_rows = m(), n_cols = n();
+  
+  for (unsigned int col=0; col<n_cols; ++col)
+    {
+      sum=0;
+      for (unsigned int row=0; row<n_rows; ++row)
+       sum += fabs(el(row,col));
+      if (sum > max)
+       max = sum;
+    }
+  return max;
+};
+
+
+template <typename number>
+number FullMatrix<number>::linfty_norm () const
+{
+  number sum=0, max=0;
+  const unsigned int n_rows = m(), n_cols = n();
+
+  for (unsigned int row=0; row<n_rows; ++row)
+    {
+      sum=0;
+      for (unsigned int col=0; col<n_cols; ++col)
+       sum += fabs(el(row,col));
+      if (sum > max)
+       max = sum;
+    }
+  return max;
+};
+
 
 template <typename number>
 void
index 10a72bc5e16be9bf9a96863ba3be6e2bd0b3ffaf..c686b4fa0065ba2beeb5eb674101379c1a805b19 100644 (file)
@@ -623,7 +623,34 @@ class SparseMatrix
                                      */
     template <typename somenumber>
     double matrix_norm (const Vector<somenumber> &v) const;
-    
+
+                                    /**
+                                     * Return the l1-norm of the matrix, i.e.
+                                     * $|M|_1=max_{all columns j}\sum_{all 
+                                     * rows i} |M_ij|$,
+                                     * (max. sum of columns).
+                                     * This is the
+                                     * natural matrix norm that is compatible
+                                     * to the l1-norm for vectors, i.e.
+                                     * $|Mv|_1\leq |M|_1 |v|_1$.
+                                     * (cf. Rannacher Numerik0)
+                                     */
+    number l1_norm () const;
+
+                                    /**
+                                     * Return the linfty-norm of the
+                                     * matrix, i.e.
+                                     * $|M|_infty=max_{all rows i}\sum_{all 
+                                     * columns j} |M_ij|$,
+                                     * (max. sum of rows).
+                                     * This is the
+                                     * natural matrix norm that is compatible
+                                     * to the linfty-norm of vectors, i.e.
+                                     * $|Mv|_infty \leq |M|_infty |v|_infty$.
+                                     * (cf. Rannacher Numerik0)
+                                     */
+    number linfty_norm () const;
+
                                     //
     template <typename somenumber>
     double residual (Vector<somenumber>& dst, const Vector<somenumber>& x,
index 0e741caa99c75d2c6a824e70ef074e91c015e5c6..b12f40b4fa5dc9a3fedc3d7a7fca45712203fd26 100644 (file)
@@ -215,6 +215,44 @@ SparseMatrix<number>::matrix_norm (const Vector<somenumber>& v) const
 };
 
 
+template <typename number>
+number SparseMatrix<number>::l1_norm () const
+{
+  Assert (cols != 0, ExcMatrixNotInitialized());
+  Assert (val != 0, ExcMatrixNotInitialized());
+
+  Vector<number> column_sums(n());
+  const unsigned int n_rows = m();
+  for (unsigned int row=0; row<n_rows; ++row)
+    for (unsigned int j=cols->rowstart[row]; j<cols->rowstart[row+1] ; ++j)
+      column_sums(cols->colnums[j])+=fabs(val[j]);
+
+  return column_sums.linfty_norm();
+};
+
+
+template <typename number>
+number SparseMatrix<number>::linfty_norm () const
+{
+  Assert (cols != 0, ExcMatrixNotInitialized());
+  Assert (val != 0, ExcMatrixNotInitialized());
+
+  const number *val_ptr = &val[cols->rowstart[0]];
+
+  number sum, max=0;
+  const unsigned int n_rows = m();
+  for (unsigned int row=0; row<n_rows; ++row)
+    {
+      sum=0;
+      const number *const val_end_of_row = &val[cols->rowstart[row+1]];
+      while (val_ptr != val_end_of_row)
+       sum += fabs(*val_ptr++);
+      if (sum > max)
+       max = sum;
+    }
+  return max;
+};
+
 
 template <typename number>
 template <typename somenumber>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.