Logo

SQL Server SYMMEIG Function

Updated 2024-03-07 15:35:35.977000

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

Syntax

SELECT * FROM [westclintech].[wct].[SYMMEIG](
  <@MatrixQuery, nvarchar(max),>
 ,<@Is3N, bit,>)

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

colNamecolDatatypecolDesc
RowNumintThe zero-based row index for the matrix
ColNumintThe zero-based column index for the matrix
ValuefloatThe value at RowNum, ColNum
Typenvarchar(4000)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.

RowNumColNumValueType
0021520.0548916024D
010D
020D
030D
100D
1132.9311831308751D
120D
130D
200D
210D
220.999697351070802D
230D
300D
310D
320D
330.014227915654616D
000.0107819695760205V
010.23936078568919V
020.779061889169004V
030.579355448969575V
100.0467476325138823V
110.48628786622379V
120.419079336335536V
13-0.765317763987238V
200.210865645105216V
210.815711666652096V
22-0.460882264857169V
230.278814803305254V
300.976337076885217V
31-0.202101465421276V
320.0708704497030608V
33-0.0299714753171836V

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.

RowNumColNumValueType
0021520.0548916024D
010D
020D
030D
100D
1132.9311831308751D
120D
130D
200D
210D
220.999697351070802D
230D
300D
310D
320D
330.014227915654616D
000.0107819695760205V
010.23936078568919V
020.779061889169004V
030.579355448969575V
100.0467476325138823V
110.48628786622379V
120.419079336335536V
13-0.765317763987238V
200.210865645105216V
210.815711666652096V
22-0.460882264857169V
230.278814803305254V
300.976337076885217V
31-0.202101465421276V
320.0708704497030608V
33-0.0299714753171836V

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.

RowNumColNumValueType
0021520.0548916024D
010D
020D
030D
100D
1132.9311831308751D
120D
130D
200D
210D
220.999697351070802D
230D
300D
310D
320D
330.014227915654616D
000.0107819695760205V
010.23936078568919V
020.779061889169004V
030.579355448969575V
100.0467476325138823V
110.48628786622379V
120.419079336335536V
13-0.765317763987238V
200.210865645105216V
210.815711666652096V
22-0.460882264857169V
230.278814803305254V
300.976337076885217V
31-0.202101465421276V
320.0708704497030608V
33-0.0299714753171836V

See Also

MUPDATE - perform elementwise operations on a matrix