Member-only story
Calculating Adjoint (Adjugate) of a NxN Matrix via MS SQL Server
Purpose: Calculation of determinant, adjoint and inverse of a matrix is essential when conducting multivariate analysis. We already discussed how to calculate the determinant value of a NxN matrix previously ( click here). For this session, we will discuss how to leverage function in MS SQL Server to get the adjoint of a NxN matrix.
How to calculate Adjoint of a Matrix
Steps:
1. We will need the determinant function ([Matrix].[determinant]) we built previously ( click here) to calculate each elements of adjoint matrix and function named[Matrix].[determinant_temp_function] to redefine the row and col number after selecting the first element of each row.
2. Create a function called [Matrix].[Adjoint] to have
- Input: Matrix as table type (MatrixTableType)
— Output: Adjoint Matrix as table type (MatrixTableType)
— Define i, j, iMax, jMax, and sign to control loop to calculate each element of decreasing matrix and transpose part.
CREATE FUNCTION [Matrix].[Adjoint]
(
@input AS Matrix.MatrixTableType READONLY
)
RETURNS @output TABLE
(
i INT,
j INT,
value FLOAT
)
AS
BEGIN
DECLARE @i INT
DECLARE @j INT
DECLARE @iMAX INT
DECLARE @jMAX INT
DECLARE @sign INT
DECLARE @value_Adj FLOAT
DECLARE @table_cofactor Matrix.MatrixTableType
SET @i = 1
SET @j = 1
SET @sign = 1
SET @iMAX = (select max(i) from…