matrixNormBand¶
Computes various norms of a matrix stored in band storage mode.
Synopsis¶
matrixNormBand (n, a, nlc, nuc)
Required Arguments¶
- int
n
(Input) - The order of matrix A.
- float
a[]
(Input) - Matrix for which the norm will be computed.
- int
nlc
(Input) - Number of lower codiagonals of A.
- int
nuc
(Input) - Number of upper codiagonals of A.
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 band symmetric storage mode.
Description¶
By default, matrixNormBand
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 band storage mode.
from __future__ import print_function
from pyimsl.math.matrixNormBand import matrixNormBand
a = [[0., 2., 3., -1.],
[1., 1., 1., 1.],
[0., 3., 4., 0.]]
nlc = 1
nuc = 1
n = 4
frobenius_norm = matrixNormBand(n, a, nlc, nuc)
inf_norm = matrixNormBand(n, a, nlc, nuc, infNorm=True)
one_norm = matrixNormBand(n, a, nlc, nuc, 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 = 6.557439
Infinity norm = 5.000000
One norm = 8.000000
Example 2¶
Compute the Frobenius norm, infinity norm, and one norm of matrix A. Matrix A is stored in symmetric band storage mode.
from __future__ import print_function
from pyimsl.math.matrixNormBand import matrixNormBand
a = [[0., 0., 7., 3., 1., 4.],
[0., 5., 1., 2., 1., 2.],
[1., 2., 4., 6., 3., 1.]]
nlc = 2
nuc = 2
n = 6
frobenius_norm = matrixNormBand(n, a, nlc, nuc, symmetric=True)
inf_norm = matrixNormBand(n, a, nlc, nuc, infNorm=True, symmetric=True)
one_norm = matrixNormBand(n, a, nlc, nuc, 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 = 16.941074
Infinity norm = 16.000000
One norm = 16.000000