Last active
May 2, 2021 18:29
-
-
Save Scriddie/522dae62c66ca4b9ff37555efd8775a9 to your computer and use it in GitHub Desktop.
determinant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate determinant of X * X | |
select @determinant := sum(product * product_sign) | |
from ( | |
select (xtx_1.value * xtx_2.value * xtx_3.value) | |
product | |
# we need to weight the row_numbers according to the inverse of their natural order | |
# to estimate degree of permutation | |
, power(-1, dense_rank() over( | |
order by 3 * xtx_1.row_num + 2 * xtx_2.row_num + 1 * xtx_3.row_num) - 1) | |
product_sign | |
from XtX xtx_1 | |
join XtX xtx_2 | |
on xtx_1.row_num != xtx_2.row_num | |
join XtX xtx_3 | |
on xtx_1.row_num != xtx_3.row_num | |
and xtx_2.row_num != xtx_3.row_num | |
where xtx_1.col_num = 1 | |
and xtx_2.col_num = 2 | |
and xtx_3.col_num = 3 | |
order by 3 * xtx_1.row_num + 2 * xtx_2.row_num + 1 * xtx_1.row_num | |
) determinant_components; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
select @Determinant := sum(product * product_sign)
This line does not work in MS SSMS --- is there another way to phrase this?