Compute Determinant using Expansion by Minors
Keywords: compute determinant using expansion minors syntax purpose m source code

| Prev | Next |  |  |  |  |  | det_by_minor_c |

Compute Determinant using Expansion by Minors
Syntax
`d = det_by_minor(a, n)`
Purpose
returns the determinant of the matrix A using expansion by minors. The elements of the n × n minor M of the matrix A are defined, for i = 0 , … , n -1 and j = 0 , … , n -1 , by M i , j = A i , j
a
The argument `a` has prototype `
const double* a
` and is a vector with size m * m . The elements of the m × m matrix A are defined, for i = 0 , … , m -1 and j = 0 , … , m -1 , by A i , j = a [ i * m + j ]
m
The argument `m` has prototype `
size_t m
` and is the number of rows (and columns) in the square matrix A .
Source Code `

    double det_by_minor(double* a, size_t m)
    {    size_t *r, *c, i;
         double value;

         r = (size_t*) malloc( (m+1) * sizeof(size_t) );
         c = (size_t*) malloc( (m+1) * sizeof(size_t) );

         assert(m <= 100);
         for(i = 0; i < m; i++)
         {    r[i] = i+1;
              c[i] = i+1;
         }
         r[m] = 0;
         c[m] = 0;

         value = det_of_minor(a, m, m, r, c);

         free(r);
         free(c);
         return value;
    }

`

Input File: compare_c/det_by_minor.c