Logo

MRORTHO

Updated 2023-10-20 15:07:32.743000

Syntax

SELECT [westclintech].[wct].[MRORTHO](
   <@m, int,>)

Description

Use the scalar function MRORTHO to generate an m-by-m random orthogonal matrix.

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.

{"columns":[{"field":"Random Ortho"}],"rows":[{"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.

{"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":"ItemValue","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"RowNum":"0","ColNum":"0","ItemValue":"-0.191535127602884"},{"RowNum":"0","ColNum":"1","ItemValue":"0.0977306803200773"},{"RowNum":"0","ColNum":"2","ItemValue":"0.631218741492654"},{"RowNum":"0","ColNum":"3","ItemValue":"0.538563181709607"},{"RowNum":"0","ColNum":"4","ItemValue":"-0.5150491323297"},{"RowNum":"1","ColNum":"0","ItemValue":"-0.256925181722918"},{"RowNum":"1","ColNum":"1","ItemValue":"-0.227310930633221"},{"RowNum":"1","ColNum":"2","ItemValue":"0.682823737870995"},{"RowNum":"1","ColNum":"3","ItemValue":"-0.308867352604093"},{"RowNum":"1","ColNum":"4","ItemValue":"0.566278988932599"},{"RowNum":"2","ColNum":"0","ItemValue":"-0.654845108341788"},{"RowNum":"2","ColNum":"1","ItemValue":"0.646001751557946"},{"RowNum":"2","ColNum":"2","ItemValue":"-0.200183370960591"},{"RowNum":"2","ColNum":"3","ItemValue":"0.165568365679679"},{"RowNum":"2","ColNum":"4","ItemValue":"0.293893442155337"},{"RowNum":"3","ColNum":"0","ItemValue":"-0.438670980620428"},{"RowNum":"3","ColNum":"1","ItemValue":"-0.0090547468604819"},{"RowNum":"3","ColNum":"2","ItemValue":"-0.00716687971463781"},{"RowNum":"3","ColNum":"3","ItemValue":"-0.692997044566636"},{"RowNum":"3","ColNum":"4","ItemValue":"-0.572004820240064"},{"RowNum":"4","ColNum":"0","ItemValue":"-0.525404035703131"},{"RowNum":"4","ColNum":"1","ItemValue":"-0.722065234921466"},{"RowNum":"4","ColNum":"2","ItemValue":"-0.308528600318225"},{"RowNum":"4","ColNum":"3","ItemValue":"0.326944751158709"},{"RowNum":"4","ColNum":"4","ItemValue":"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.

{"columns":[{"field":"0","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"2","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"3","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"4","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"0":"-0.122114882812285","1":"-0.395863947216","2":"-0.153213896228385","3":"0.420799767645121","4":"0.792358976880201"},{"0":"-0.0288920409888247","1":"-0.594831416732544","2":"0.254538830632621","3":"-0.748043243040445","4":"0.144852082750529"},{"0":"-0.556646243755227","1":"0.428805531868408","2":"-0.49541620929494","3":"-0.436813184882699","4":"0.264627655834974"},{"0":"-0.760988315619334","1":"-0.00331030095866591","2":"0.601259619233508","3":"0.214083465119949","4":"-0.116365654897932"},{"0":"-0.308698798454557","1":"-0.552794879416532","2":"-0.552073487454074","3":"0.163466735350695","4":"-0.517316502740494"}]}

See Also

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