lines 8-142 of file: cpp/include/cmpad/algo/det_of_minor.hpp {xrst_begin_parent cpp_det_of_minor} {xrst_spell obj } C++ Determinant of a Minor ########################## Syntax ****** | |tab| ``# include `` | |tab| *d* = ``cmpad::det_of_minor`` ( *a* , *n* , *m* , *r* , *c* ) Prototype ********* {xrst_literal // BEGIN PROTOTYPE // END PROTOTYPE } Purpose ******* This template function computes the determinant of a minor of the matrix :math:`A` using expansion by minors. It is for example and testing purposes only. Expansion by minors is chosen as an example because it uses a lot of floating point operations yet does not require much source code. This is not an efficient method for computing a determinant; for example, using an LU factorization would be faster. Minor ***** The elements of the :math:`m \times m` minor :math:`M` of the matrix :math:`A` are defined, for :math:`i = 0 , \ldots , m-1` and :math:`j = 0 , \ldots , m-1`, by .. math:: M_{i,j} = A_{R(i), C(j)} where the function :math:`R(i)` is defined by the :ref:`argument r` and :math:`C(j)` is defined by the :ref:`argument c` . Determinant of A **************** If the following conditions hold, the minor is the entire matrix :math:`A` and hence ``det_of_minor`` will return the determinant of :math:`A`: #. :math:`m = n`. #. for :math:`i = 0 , \ldots , n-1`, :math:`r[i] = i+1`, and :math:`r[n] = 0`. #. for :math:`j = 0 , \ldots , n-1`, :math:`c[j] = j+1`, and :math:`c[n] = 0`. Vector ****** This type satisfies the conditions for a fun_obj :ref:`cpp_fun_obj@Vector` . a * The elements of the :math:`n \times n` matrix :math:`A` are defined, for :math:`i = 0 , \ldots , n-1` and :math:`j = 0 , \ldots , n-1`, by .. math:: A_{i,j} = a[ i * n + j] n * This is the number of rows (and columns) in the square matrix :math:`A`. m * This is the number of rows (and columns) in the square minor :math:`M`. r * This defines the function :math:`R(i)` which specifies the rows of the minor :math:`M`. To be specific, the function :math:`R(i)` for :math:`i = 1, \ldots , m-1` is defined by .. math:: \begin{eqnarray} R(0) & = & r[n] \\ R(i) & = & r[ R(i-1) ] \end{eqnarray} All the elements of *r* have value less than or equal *n* ; :math:`R(i) < n` and :math:`r[ R(m-1) ] = n` . The elements of vector *r* are modified during the computation, and restored to their original value before the return from ``det_of_minor`` . c * This defines the function :math:`C(i)` which specifies the columns of the minor :math:`M`. To be specific, the function :math:`C(i)` for :math:`j = 1, \ldots , m-1` is defined by .. math:: \begin{eqnarray} C(0) & = & c[n] \\ C(j) & = & c[ C(j-1) ] \end{eqnarray} All the elements of *c* must have value less than or equal *n* ; :math:`C(j) < n` and :math:`c[ C(m-1) ] = n` . The elements of vector *c* are modified during the computation, and restored to their original value before the return from ``det_of_minor`` . d * The return value *d* is equal to the determinant of the minor :math:`M` and has the same type as the elements of *a*. {xrst_toc_table after cpp/xam/det_of_minor.cpp } Example ******* :ref:`xam_det_of_minor.cpp-name` contains an example and test of ``det_of_minor`` . {xrst_end cpp_det_of_minor}