![]() | How To Do Matrix Computation |
SQX - Structured Query Matrix allow Matrix and Vector computation inside SQL Server (OLTP) with support for transactions.
-- NOTE: The print and ToString() method are useful to test or debug -- You can load a matrix from a Query or from a special function declare @A sqx.Matrix = sqx.RandomMatrix(4,4,2) -- You can also load a matrix from parse declare @B sqx.Matrix = '3,2,1;1,2,3;1,5,9' print '*** B=A ***' -- You can use SET or SELECT select @B = @A print @B.ToString() print '*** AB ***' print @A.Product(@B).ToString() print '*** BA ***' print @B.Product(@A).ToString() print '*** e(A) * e(B) ***' print @A.Exponential().Product(@B.Exponential()).ToString() print '*** e(A + B) *** NOTE: e(A) * e(B) = e(A + B) if and only if AB = BA' print @A.Addition(@B).Exponential().ToString() print '*** e(A) * e(-B) = I *** (With small error)' print @A.Exponential().Product(@B.Minus().Exponential()).ToString() print '*** e(A) * e(-B) = I *** Round(14)' print @A.Exponential().Product(@B.Minus().Exponential()).Round(14).ToString()
/*
*** B=A ***
0.771093898346226,0.404162594771088,0.165998670349828,0.985047052607428;
0.109004633551931,0.306680407983568,0.802140461188806,0.445546678940554;
0.224983153969507,0.0112066529743404,0.765367340652909,0.0287435907073056;
0.00756119052300285,0.510022416948351,0.382094984586395,0.279408783316337
*** AB ***
0.683436428454136,0.939852428295362,0.95562723126576,1.21963927001865;
0.30131934752434,0.374336572021181,1.04826865116159,0.391561182853691;
0.347116808368387,0.117603717983305,0.643106162181641,0.25664269700688;
0.149502792331879,0.306256582170913,0.809568481304923,0.323738972538041
*** BA ***
0.683436428454136,0.939852428295362,0.95562723126576,1.21963927001865;
0.30131934752434,0.374336572021181,1.04826865116159,0.391561182853691;
0.347116808368387,0.117603717983305,0.643106162181641,0.25664269700688;
0.149502792331879,0.306256582170913,0.809568481304923,0.323738972538041
*** e(A) * e(B) ***
6.77850944538221,6.17284082598166,9.27702076218408,8.76243363426655;
2.47378284657182,3.86994683810226,7.62119406268057,3.70862481083082;
2.40470006112609,1.37591910752465,6.28663273989425,2.15354068712646;
1.44897501311771,2.69366101893238,5.32755388118214,3.58293936490456
*** e(A + B) *** NOTE: e(A) * e(B) = e(A + B) if and only if AB = BA
6.77850944538221,6.17284082598166,9.27702076218408,8.76243363426656;
2.47378284657182,3.86994683810226,7.62119406268057,3.70862481083082;
2.40470006112609,1.37591910752466,6.28663273989425,2.15354068712646;
1.44897501311771,2.69366101893238,5.32755388118214,3.58293936490456
*** e(A) * e(-B) = I *** (With small error)
1,3.33066907387547E-16,-1.11022302462516E-16,1.11022302462516E-15;
2.08166817117217E-17,1,3.46944695195361E-16,3.33066907387547E-16;
6.93889390390723E-18,5.55111512312578E-17,1,1.38777878078145E-16;
-1.38777878078145E-17,0,2.4980018054066E-16,1
*** e(A) * e(-B) = I *** Round(14)
1,0,0,0;
0,1,0,0;
0,0,1,0;
0,0,0,1*/