det_by_minor_c

View page source

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 \times n\) minor \(M\) of the matrix \(A\) are defined, for \(i = 0 , \ldots , n-1\) and \(j = 0 , \ldots , 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 \times m\) matrix \(A\) are defined, for \(i = 0 , \ldots , m-1\) and \(j = 0 , \ldots , 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;
}