Login     Register

        Contact Us     Search

XLeratorDB/math Documentation

SQL Server matrix rank


MRANK

Updated: 06 April 2016

Use MRANK to calculate the rank of a matrix. The rank of the matrix is calculated from its singular value decomposition where the rank is the number of elements in in the diagonal matrix which are greater than the tolerance. The tolerance is calculated as the W0 * MAX(m, n) * eps where m is the number of rows in the input matrix, n is the number of columns in the input matrix and eps is 2-53.
Syntax
SELECT [wct].[MRANK](
  <@MatrixQuery, nvarchar(max),>
 ,<@IS3N, bit,>)
Arguments
@MatrixQuery
the SELECT statement, as text, used to return the input matrix for this function. The SELECT statement specifies the column names from the table or view or can be used to enter the matrix values directly. Data returned from the @MatrixQuery select must be of the type float or of a type that implicitly converts to float.
@Is3N
a bit value identifying the form for the resultant table returned by @MatrixQuery. Enter 'True' for a resultant table in 3rd normal form. Enter 'False' for a de-normalized table in 'spreadsheet' form.
Return Type
float
Remarks
·         If @MatrixQuery does not return a square or a rectangular matrix an error will be generated.
·         Available in XLeratorDB / math 2008 only
Examples
Example #1
In the example we calculate the rank of a matrix in 'spreadsheet' format; i.e. in row/column format.
SELECT
   wct.MRANK('
       SELECT *
       FROM (VALUES
        (1,1,1,1)
       ,(1,2,4,8)
       ,(1,3,9,27)
       ,(1,4,16,64)
       ,(1,5,25,125)
       )n(x1,x2,x3,x4)'
       ,0) as [Matrix Rank]
This produces the following result.

Example #2
Using the same matrix content as Example #1 but with the data in 3rd normal form.
SELECT
   wct.MRANK(
   'SELECT *
   FROM (VALUES
    (0,0,1)
   ,(0,1,1)
   ,(0,2,1)
   ,(0,3,1)
   ,(1,0,1)
   ,(1,1,2)
   ,(1,2,4)
   ,(1,3,8)
   ,(2,0,1)
   ,(2,1,3)
   ,(2,2,9)
   ,(2,3,27)
   ,(3,0,1)
   ,(3,1,4)
   ,(3,2,16)
   ,(3,3,64)
   ,(4,0,1)
   ,(4,1,5)
   ,(4,2,25)
   ,(4,3,125)
   )n(r,c,x)'
   ,1) as [Matrix Rank]
This produces the following result.

Example #3
With the matrix in CSV format, with the columns separated by commas and the rows separated by semi-colons.
SELECT wct.MRANK('1,1,1,1;1,2,4,8;1,3,9,27;1,4,16,64;1,5,25,125', 0) as [Matrix Rank]
This produces the following result.

 

See Also

 



Copyright 2008-2024 Westclintech LLC         Privacy Policy        Terms of Service