![]() |
Prev | Next |
# include <cppad/speed/det_of_minor.hpp>
d = det_of_minor(
a,
m,
n,
r,
c)
det_of_minor
is defined in the CppAD
namespace by including
the file cppad/speed/det_of_minor.hpp
(relative to the CppAD distribution directory).
It is only intended for example and testing purposes,
so it is not automatically included by
cppad.hpp
.
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_{R(i), C(j)}
\]
where the functions
R(i)
is defined by the argument r
and
C(j)
is defined by the argument c
.
This template function
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
(on the order of m factorial floating point operations and
about 70 lines of source code including comments).
This is not an efficient method for computing a determinant;
for example, using an LU factorization would be better.
A
and hence det_of_minor
will return the determinant of
A
:
n = m
.
i = 0 , \ldots , m-1
,
r[i] = i+1
,
and
r[m] = 0
.
j = 0 , \ldots , m-1
,
c[j] = j+1
,
and
c[m] = 0
.
const std::vector<
Scalar>&
a
and is a vector with size
m * m
(see description of Scalar
below).
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]
\]
size_t
m
and is the size of the square matrix
A
.
size_t
n
and is the size of the square minor
M
.
std::vector<size_t>&
r
and is a vector with
m + 1
elements.
This vector defines the function
R(i)
which specifies the rows of the minor
M
.
To be specific, the function
R(i)
for
i = 0, \ldots , n-1
is defined by
\[
\begin{array}{rcl}
R(0) & = & r[m]
\\
R(i+1) & = & r[ R(i) ]
\end{array}
\]
All the elements of r must have value
less than or equal m.
The elements of vector r are modified during the computation,
and restored to their original value before the return from
det_of_minor
.
std::vector<size_t>&
c
and is a vector with
m + 1
elements
This vector defines the function
C(i)
which specifies the rows of the minor
M
.
To be specific, the function
C(i)
for
j = 0, \ldots , n-1
is defined by
\[
\begin{array}{rcl}
C(0) & = & c[m]
\\
C(j+1) & = & c[ C(j) ]
\end{array}
\]
All the elements of c must have value
less than or equal m.
The elements of vector c are modified during the computation,
and restored to their original value before the return from
det_of_minor
.
Scalar
d
and is equal to the determinant of the minor
M
.
int
,
the Scalar must support the following operations:
Syntax | Description | Result Type |
Scalar x
| default constructor for Scalar object. | |
x = i
| set value of x to current value of i | |
x = y
| set value of x to current value of y | |
x + y
| value of x plus y | Scalar |
x - y
| value of x minus y | Scalar |
x * y
| value of x times value of y | Scalar |
det_of_minor.hpp
.
It returns true if it succeeds and false otherwise.