Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server MDETERM function


 
Updated: 17 August 2010

Use MDETERM_q to calculate the determinant of an N x N matrix, where N specifies the number of columns in the matrix. For matrices in normalized form, use the MDETERMN_q function.
Syntax
SELECT [wctMath].[wct].[MDETERM_q] (
   <@Matrix_RangeQuery, nvarchar(max),>)
Arguments
@Matrix_RangeQuery
the select statement, as text, used to determine the N x N matrix to be used in this function. If you are specify data in a table or a view, then you enter the column names to be included in the determinant calculation. If you are entering the values directly using UNION ALL, then each part of the SELECT must have the same number of columns. Data returned from the @Matrix_RangeQuery select must be of the type float or of a type that implicitly converts to float.
Return Types
float
Remarks
·         If the number of rows in the matrix is not equal to the number of columns, MDETERM will return an error.
·         No GROUP BY is required for this function even though it produces aggregated results.
·         Use the MDETERM function for simpler queries.
·         Use MDETERMN_q for a table in normal form.
·         The function returns an error if the matrix contains NULL.
·         You can directly pass the matrix into @Matrix_RangeQuery in the form of a SELECT statement without referring to a table or a view.
Examples
In this example, we will enter a simple 6 x 6 matrix to calculate 6!
 
SELECT wct.MDETERM_q(
'SELECT 1,0,0,0,0,0 UNION ALL
 SELECT 0,2,0,0,0,0 UNION ALL
 SELECT 0,0,3,0,0,0 UNION ALL
 SELECT 0,0,0,4,0,0 UNION ALL
 SELECT 0,0,0,0,5,0 UNION ALL
 SELECT 0,0,0,0,0,6'
 ) as [|A|]

This produces the following result
                   |A|
----------------------
                   720
 
(1 row(s) affected)


Here is another example, with a 4 x 4 matrix
SELECT wct.MDETERM_q(
   'SELECT 1,2,3,10 UNION ALL
    SELECT 6,4,4,11 UNION ALL
    SELECT 7,8,9,12 UNION ALL
    SELECT 16,15,14,13'
) as [|A|]

This produces the following result
                   |A|
----------------------
                   208
 
(1 row(s) affected)


To calculate the determinant from a table, for example,
CREATE TABLE #m(
      Col1 float,
      Col2 float,
      Col3 float,
      Col4 float
)
 
INSERT INTO #m
SELECT 1,2,3,10 UNION ALL
SELECT 6,4,4,11 UNION ALL
SELECT 7,8,9,12 UNION ALL
SELECT 16,15,14,13
 
SELECT wct.MDETERM_q(
      'SELECT *
       FROM #m'
      ) as [|A|]

This produces the following result
                   |A|
----------------------
                   208
 
(1 row(s) affected)

See Also

·         Blog Post - SQL Server Matrix Functions


Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service