SQL Server MRORTHO Function
Updated 2023-10-20 15:07:32.743000
Description
Use the scalar function MRORTHO to generate an m-by-m random orthogonal matrix.
Syntax
SELECT [westclintech].[wct].[MRORTHO](
<@m, int,>)
Arguments
@m
the number of rows and columns in returned matrix. @m must be of the type int or of a type that implicitly converts to int.
Return Type
nvarchar(max)
Remarks
m must be greater than zero.
Examples
Example #1
In this example we generate a random 4-by-4 random orthogonal matrix. The returned matrix is a string where the columns are separated by commas and the rows are separated by semicolons. Your results will be different.
SELECT wct.MRORTHO(4) as [Random Ortho];
This produces the following result.
| Random Ortho |
|---|
| -0.545829755043242,-0.0228991621437602,0.594451350513863,-0.590061944845448;-0.233244406455275,-0.0578296939223679,0.566225861771682,0.788442164536555;-0.796825056795052,0.171861704431101,-0.55258724022565,0.173726006554572;-0.112857229410982,-0.983155587597404,-0.143747025266473,-0.00226474561948396 |
Example #2
In this example we generate a 5-by-5 random orthogonal matrix and use the MATRIX function to convert the output to 3rd normal form. Your results will be different.
SELECT *
FROM wct.MATRIX(wct.MRORTHO(5));
This produces the following result.
| RowNum | ColNum | ItemValue |
|---|---|---|
| 0 | 0 | -0.191535127602884 |
| 0 | 1 | 0.0977306803200773 |
| 0 | 2 | 0.631218741492654 |
| 0 | 3 | 0.538563181709607 |
| 0 | 4 | -0.5150491323297 |
| 1 | 0 | -0.256925181722918 |
| 1 | 1 | -0.227310930633221 |
| 1 | 2 | 0.682823737870995 |
| 1 | 3 | -0.308867352604093 |
| 1 | 4 | 0.566278988932599 |
| 2 | 0 | -0.654845108341788 |
| 2 | 1 | 0.646001751557946 |
| 2 | 2 | -0.200183370960591 |
| 2 | 3 | 0.165568365679679 |
| 2 | 4 | 0.293893442155337 |
| 3 | 0 | -0.438670980620428 |
| 3 | 1 | -0.0090547468604819 |
| 3 | 2 | -0.00716687971463781 |
| 3 | 3 | -0.692997044566636 |
| 3 | 4 | -0.572004820240064 |
| 4 | 0 | -0.525404035703131 |
| 4 | 1 | -0.722065234921466 |
| 4 | 2 | -0.308528600318225 |
| 4 | 3 | 0.326944751158709 |
| 4 | 4 | 0.0221275452799954 |
Example #3
In this example we generate the 5-by-5 random orthogonal matrix and pivot the MATRIX output into 'spreadsheet' format. Your results will be different.
SELECT [0],
[1],
[2],
[3],
[4]
FROM wct.MATRIX(wct.MRORTHO(5)) d
PIVOT
(
MAX(ItemValue)
FOR ColNum IN ([0], [1], [2], [3], [4])
) pvt
ORDER BY RowNum;
This produces the following result.
| 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|
| -0.122114882812285 | -0.395863947216 | -0.153213896228385 | 0.420799767645121 | 0.792358976880201 |
| -0.0288920409888247 | -0.594831416732544 | 0.254538830632621 | -0.748043243040445 | 0.144852082750529 |
| -0.556646243755227 | 0.428805531868408 | -0.49541620929494 | -0.436813184882699 | 0.264627655834974 |
| -0.760988315619334 | -0.00331030095866591 | 0.601259619233508 | 0.214083465119949 | -0.116365654897932 |
| -0.308698798454557 | -0.552794879416532 | -0.552073487454074 | 0.163466735350695 | -0.517316502740494 |
See Also
SVD - Economy-sized singular value decomposition using a formatted matrix as input