matrixNormCoordinate

Computes various norms of a matrix stored in coordinate format.

Synopsis

matrixNormCoordinate (m, n, a)

Required Arguments

int m (Input)
The number of rows in matrix A.
int n (Input)
The number of columns in matrix A.
sparse_elem a[] (Input)
Matrix for which the norm will be computed.

Return Value

The requested norm of the input matrix, by default, the Frobenius norm. If the norm cannot be computed, NaN is returned.

Optional Arguments

oneNorm,
Compute the 1-norm of matrix A.
infNorm,
Compute the infinity norm of matrix A.
symmetric,
Matrix A is stored in symmetric coordinate format.

Description

By default, matrixNormCoordinate computes the Frobenius norm

\[\|A\|_2 = \left[\sum_{i=0}^{m-1} \sum_{j=0}^{n-1} A_{ij}^2\right]^{\frac{1}{2}}\]

If the option oneNorm is selected, the 1-norm

\[\|A\|_1 = \max_{0 \leq j \leq n-1} \sum_{i=0}^{m-1} \left|A_{ij}\right|\]

is returned. If the option infNorm is selected, the infinity norm

\[\|A\|_{\infty} = \max_{0 \leq i \leq m-1} \sum_{j=0}^{n-1} \left|A_{ij}\right|\]

is returned.

Examples

Example 1

Compute the Frobenius norm, infinity norm, and one norm of matrix A. Matrix A is stored in coordinate format.

from __future__ import print_function
from pyimsl.math.matrixNormCoordinate import matrixNormCoordinate

a = [[0, 0, 10.0], [1, 1, 10.0], [1, 2, -3],
     [1, 3, -1], [2, 2, 15], [3, 0, -2],
     [3, 3, 10], [3, 4, -1], [4, 0, -1],
     [4, 3, -5], [4, 4, 1], [4, 5, -3],
     [5, 0, -1], [5, 1, -2], [5, 5, 6.]]
m = 6
n = 6

frobenius_norm = matrixNormCoordinate(m, n, a)

inf_norm = matrixNormCoordinate(m, n, a, infNorm=True)

one_norm = matrixNormCoordinate(m, n, a, oneNorm=True)

print("Frobenius norm = %10.6f" % frobenius_norm)
print("Infinity norm  = %10.6f" % inf_norm)
print("One norm       = %10.6f" % one_norm)

Output

Frobenius norm =  24.839485
Infinity norm  =  15.000000
One norm       =  18.000000

Example 2

Compute the Frobenius norm, infinity norm and one norm of matrix A. Matrix A is stored in symmetric coordinate format.

from __future__ import print_function
from pyimsl.math.matrixNormCoordinate import matrixNormCoordinate

a = [[0, 0, 10.], [0, 2, -1.0], [0, 5, 5],
     [1, 3, 2], [1, 4, 3], [2, 2, 3], [2, 5, 4],
     [4, 4, -1], [4, 5, 4]]
m = 6
n = 6

frobenius_norm = matrixNormCoordinate(m, n, a, symmetric=True)

inf_norm = matrixNormCoordinate(m, n, a, infNorm=True, symmetric=True)

one_norm = matrixNormCoordinate(m, n, a, oneNorm=True, symmetric=True)

print("Frobenius norm = %10.6f" % frobenius_norm)
print("Infinity norm  = %10.6f" % inf_norm)
print("One norm       = %10.6f" % one_norm)

Output

Frobenius norm =  15.874508
Infinity norm  =  16.000000
One norm       =  16.000000