Logo

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.

RowNumColNumItemValue
00-0.191535127602884
010.0977306803200773
020.631218741492654
030.538563181709607
04-0.5150491323297
10-0.256925181722918
11-0.227310930633221
120.682823737870995
13-0.308867352604093
140.566278988932599
20-0.654845108341788
210.646001751557946
22-0.200183370960591
230.165568365679679
240.293893442155337
30-0.438670980620428
31-0.0090547468604819
32-0.00716687971463781
33-0.692997044566636
34-0.572004820240064
40-0.525404035703131
41-0.722065234921466
42-0.308528600318225
430.326944751158709
440.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.

01234
-0.122114882812285-0.395863947216-0.1532138962283850.4207997676451210.792358976880201
-0.0288920409888247-0.5948314167325440.254538830632621-0.7480432430404450.144852082750529
-0.5566462437552270.428805531868408-0.49541620929494-0.4368131848826990.264627655834974
-0.760988315619334-0.003310300958665910.6012596192335080.214083465119949-0.116365654897932
-0.308698798454557-0.552794879416532-0.5520734874540740.163466735350695-0.517316502740494

See Also

SVD - Economy-sized singular value decomposition using a formatted matrix as input