MNORM
Updated 2023-10-17 13:35:11.157000
Syntax
SELECT [westclintech].[wct].[MNORM] (
<@Matrix, nvarchar(max),>
,<@NormType, nvarchar(4000),>)
Description
Use the scalar function MNORM to compute a matrix norm. The norm can be the one ('O') norm, the infinity ('I') norm, the Frobenius ('F') norm, the maximum modulus ('M') among elements of a matrix, or the '2'-norm.
Arguments
@Matrix
The string representation of the matrix with columns separated by commas and rows separated by semi-colons.
@NormType
The matrix norm to be calculated
Return Type
float
Remarks
If NormType IS NULL then NormType = '0'.
Set NormType = '0' or '1' for the 1-norm, the maximum absolute column sum.
Set NormType = 'I' for the infinity-norm, the maximum absolute row sum.
Set NormType = 'M' for the maximum modulus of all the matrix elements.
Set NormType = 'F' for the Frobenius norm, the square root of the sum of the square of the elements.
Set NormType = '2' for the 2-norm, the largest singular value of Matrix.
Examples
Example #1
--Matrix dimension
DECLARE @n as int = 9;
--Create the Hilbert Matrix
DECLARE @H as nvarchar(max) =
(
SELECT wct.NMATRIX2STRING(i, j, val)
FROM
(
SELECT i.SeriesValue - 1 as i,
j.SeriesValue - 1 as j,
1 / (i.SeriesValue + j.SeriesValue - 1) as val
FROM wct.SeriesFloat(1, @n, NULL, NULL, NULL) i
CROSS APPLY wct.SeriesInt(1, @n, NULL, NULL, NULL) j
) n
);
--Calculate each norm
SELECT x.type,
wct.MNORM(@H, x.type) as norm
FROM
(
VALUES
('1'),
('F'),
('M'),
('I'),
('2')
) x (type)
ORDER BY 1;
This produces the following result.
{"columns":[{"field":"type"},{"field":"norm","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"type":"1","norm":"2.82896825396825"},{"type":"2","norm":"1.72588266090185"},{"type":"F","norm":"1.75587190971665"},{"type":"I","norm":"2.82896825396825"},{"type":"M","norm":"1"}]}
See Also
SUMPRODUCT - calculate the sum of elementwise multiplication on a group of matrices
SUMX2MY2 - the sum of the square of the elementwise differences of 2 matrices
SUMX2PY2 - the sum of the sum of the squares for corresponding elements in 2 matrices