matrixNorm

Computes various norms of a rectangular matrix.

Synopsis

matrixNorm (a)

Required Arguments

float a[] (Input)
Matrix for which the norm will be computed.

Return Value

The requested norm of the input matrix. 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.

Description

By default, matrixNorm 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.

Example

Compute the Frobenius norm, infinity norm, and one norm of matrix A.

from __future__ import print_function
from pyimsl.math.matrixNorm import matrixNorm

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

frobenius_norm = matrixNorm(a)

inf_norm = matrixNorm(a, infNorm=True)

one_norm = matrixNorm(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 =  15.684387
Infinity norm  =  20.000000
One norm       =  17.000000