SYMMEIG
Updated 2024-03-07 15:35:35.977000
Syntax
SELECT * FROM [westclintech].[wct].[SYMMEIG](
<@MatrixQuery, nvarchar(max),>
,<@Is3N, bit,>)
Description
Use the table-valued function SYMMEIG to return the D and V matrices representing the eigenvalues and eigenvectors of a real symmetric matrix. The input into the function is an SQL statement having a resultant table which is a real, symmetric matrix. The resultant table can be in either 3rd-normal or 'spreadsheet' form. SYMMEIG returns a table in third normal form containing the D and V matrices such that:
\textbf{A}=\textbf{VDV}^T
Arguments
@MatrixQuery
An SQL statement which upon execution returns a real symmetric matrix or the string representation of the matrix with the columns separated by commas and the rows separated by semicolons.
@Is3N
A bit value which indicates whether the resultant table returned by @MatrixQuery is in 3rd normal form. Enter TRUE for a resultant table in 3rd normal form.
Return Type
table
{"columns": [{"field": "colName", "headerName": "Name", "header": "name"}, {"field": "colDatatype", "headerName": "Type", "header": "type"}, {"field": "colDesc", "headerName": "Description", "header": "description", "minWidth": 1000}], "rows": [{"id": "97cb6186-11cf-4ce9-97b8-44036017b601", "colName": "RowNum", "colDatatype": "int", "colDesc": "The zero-based row index for the matrix"}, {"id": "5145f3a1-4b42-48c8-ba85-5ef93f4962fe", "colName": "ColNum", "colDatatype": "int", "colDesc": "The zero-based column index for the matrix"}, {"id": "b379a8e5-331a-49ff-83ae-26694c435be7", "colName": "Value", "colDatatype": "float", "colDesc": "The value at RowNum, ColNum"}, {"id": "af02cf72-eeac-47ea-ad6d-6bf7671ab7a6", "colName": "Type", "colDatatype": "nvarchar(4000)", "colDesc": "The D or V matrix"}]}
Remarks
If @Is3N is NULL then @Is3N = FALSE.
Type is either 'D' or 'V'.
Examples
Example #1
In this example we supply @A as a real symmetric matrix and return the D and V matrices.
DECLARE @A as varchar(max) = '5,15,55,225;15,55,225,979;55,225,979,4425;225,979,
4425,20515';
SELECT *
FROM wct.SYMMEIG(@A, NULL);
This produces the following result.
{"columns":[{"field":"RowNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ColNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Value","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Type"}],"rows":[{"RowNum":"0","ColNum":"0","Value":"21520.0548916024","Type":"D"},{"RowNum":"0","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"0","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"0","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"1","Value":"32.9311831308751","Type":"D"},{"RowNum":"1","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"2","Value":"0.999697351070802","Type":"D"},{"RowNum":"2","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"3","Value":"0.014227915654616","Type":"D"},{"RowNum":"0","ColNum":"0","Value":"0.0107819695760205","Type":"V"},{"RowNum":"0","ColNum":"1","Value":"0.23936078568919","Type":"V"},{"RowNum":"0","ColNum":"2","Value":"0.779061889169004","Type":"V"},{"RowNum":"0","ColNum":"3","Value":"0.579355448969575","Type":"V"},{"RowNum":"1","ColNum":"0","Value":"0.0467476325138823","Type":"V"},{"RowNum":"1","ColNum":"1","Value":"0.48628786622379","Type":"V"},{"RowNum":"1","ColNum":"2","Value":"0.419079336335536","Type":"V"},{"RowNum":"1","ColNum":"3","Value":"-0.765317763987238","Type":"V"},{"RowNum":"2","ColNum":"0","Value":"0.210865645105216","Type":"V"},{"RowNum":"2","ColNum":"1","Value":"0.815711666652096","Type":"V"},{"RowNum":"2","ColNum":"2","Value":"-0.460882264857169","Type":"V"},{"RowNum":"2","ColNum":"3","Value":"0.278814803305254","Type":"V"},{"RowNum":"3","ColNum":"0","Value":"0.976337076885217","Type":"V"},{"RowNum":"3","ColNum":"1","Value":"-0.202101465421276","Type":"V"},{"RowNum":"3","ColNum":"2","Value":"0.0708704497030608","Type":"V"},{"RowNum":"3","ColNum":"3","Value":"-0.0299714753171836","Type":"V"}]}
Example #2
Using the same values, with the matrix passed in as SQL which produces a resultant table not in 3 rd -normal form.
SELECT *
FROM wct.SYMMEIG(
'SELECT * FROM (VALUES (5,15,55,225),(15,55,225,979),(55,225,
979,4425),(225,979,4425,20515))n(x1,x2,x3,x4)',
'False'
);
This produces the following result.
{"columns":[{"field":"RowNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ColNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Value","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Type"}],"rows":[{"RowNum":"0","ColNum":"0","Value":"21520.0548916024","Type":"D"},{"RowNum":"0","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"0","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"0","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"1","Value":"32.9311831308751","Type":"D"},{"RowNum":"1","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"2","Value":"0.999697351070802","Type":"D"},{"RowNum":"2","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"3","Value":"0.014227915654616","Type":"D"},{"RowNum":"0","ColNum":"0","Value":"0.0107819695760205","Type":"V"},{"RowNum":"0","ColNum":"1","Value":"0.23936078568919","Type":"V"},{"RowNum":"0","ColNum":"2","Value":"0.779061889169004","Type":"V"},{"RowNum":"0","ColNum":"3","Value":"0.579355448969575","Type":"V"},{"RowNum":"1","ColNum":"0","Value":"0.0467476325138823","Type":"V"},{"RowNum":"1","ColNum":"1","Value":"0.48628786622379","Type":"V"},{"RowNum":"1","ColNum":"2","Value":"0.419079336335536","Type":"V"},{"RowNum":"1","ColNum":"3","Value":"-0.765317763987238","Type":"V"},{"RowNum":"2","ColNum":"0","Value":"0.210865645105216","Type":"V"},{"RowNum":"2","ColNum":"1","Value":"0.815711666652096","Type":"V"},{"RowNum":"2","ColNum":"2","Value":"-0.460882264857169","Type":"V"},{"RowNum":"2","ColNum":"3","Value":"0.278814803305254","Type":"V"},{"RowNum":"3","ColNum":"0","Value":"0.976337076885217","Type":"V"},{"RowNum":"3","ColNum":"1","Value":"-0.202101465421276","Type":"V"},{"RowNum":"3","ColNum":"2","Value":"0.0708704497030608","Type":"V"},{"RowNum":"3","ColNum":"3","Value":"-0.0299714753171836","Type":"V"}]}
Example #3
Using the same values, with the matrix passed in as SQL which produces a result in 3rd normal form.
SELECT *
INTO #t
FROM
(
VALUES
(0, 0, 5),
(0, 1, 15),
(0, 2, 55),
(0, 3, 225),
(1, 0, 15),
(1, 1, 55),
(1, 2, 225),
(1, 3, 979),
(2, 0, 55),
(2, 1, 225),
(2, 2, 979),
(2, 3, 4425),
(3, 0, 225),
(3, 1, 979),
(3, 2, 4425),
(3, 3, 20515)
) n (r, c, x);
SELECT *
FROM wct.SYMMEIG('SELECT * FROM #t', 'True');
This produces the following result.
{"columns":[{"field":"RowNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ColNum","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Value","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Type"}],"rows":[{"RowNum":"0","ColNum":"0","Value":"21520.0548916024","Type":"D"},{"RowNum":"0","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"0","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"0","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"1","Value":"32.9311831308751","Type":"D"},{"RowNum":"1","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"1","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"2","ColNum":"2","Value":"0.999697351070802","Type":"D"},{"RowNum":"2","ColNum":"3","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"0","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"1","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"2","Value":"0","Type":"D"},{"RowNum":"3","ColNum":"3","Value":"0.014227915654616","Type":"D"},{"RowNum":"0","ColNum":"0","Value":"0.0107819695760205","Type":"V"},{"RowNum":"0","ColNum":"1","Value":"0.23936078568919","Type":"V"},{"RowNum":"0","ColNum":"2","Value":"0.779061889169004","Type":"V"},{"RowNum":"0","ColNum":"3","Value":"0.579355448969575","Type":"V"},{"RowNum":"1","ColNum":"0","Value":"0.0467476325138823","Type":"V"},{"RowNum":"1","ColNum":"1","Value":"0.48628786622379","Type":"V"},{"RowNum":"1","ColNum":"2","Value":"0.419079336335536","Type":"V"},{"RowNum":"1","ColNum":"3","Value":"-0.765317763987238","Type":"V"},{"RowNum":"2","ColNum":"0","Value":"0.210865645105216","Type":"V"},{"RowNum":"2","ColNum":"1","Value":"0.815711666652096","Type":"V"},{"RowNum":"2","ColNum":"2","Value":"-0.460882264857169","Type":"V"},{"RowNum":"2","ColNum":"3","Value":"0.278814803305254","Type":"V"},{"RowNum":"3","ColNum":"0","Value":"0.976337076885217","Type":"V"},{"RowNum":"3","ColNum":"1","Value":"-0.202101465421276","Type":"V"},{"RowNum":"3","ColNum":"2","Value":"0.0708704497030608","Type":"V"},{"RowNum":"3","ColNum":"3","Value":"-0.0299714753171836","Type":"V"}]}