Prev  Next 
Syntax
include <cppad/utility/lu_solve.hpp>
signdet = LuSolve(n, m, A, B, X, logdet)
A
to
compute its determinant
and solve for
X
in the linear of equation
@[@
A * X = B
@]@
where
A
is an
n
by
n
matrix,
X
is an
n
by
m
matrix, and
B
is an @(@
n x m
@)@ matrix.
cppad/lu_solve.hpp
is included by cppad/cppad.hpp
but it can also be included separately with out the rest of
the CppAD
routines.
B
depends on the solution corresponding to another
right hand side (with the same value of
A
).
In this case only one call to LuFactor
is required
but there will be multiple calls to LuInvert
.
signdet
is a int
value
that specifies the sign factor for the determinant of
A
.
This determinant of
A
is zero if and only if
signdet
is zero.
n
has type size_t
and specifies the number of rows in the matrices
A
,
X
,
and
B
.
The number of columns in
A
is also equal to
n
.
m
has type size_t
and specifies the number of columns in the matrices
X
and
B
.
If
m
is zero,
only the determinant of
A
is computed and
the matrices
X
and
B
are not used.
A
has the prototype
const FloatVector &A
and the size of
A
must equal @(@
n * n
@)@
(see description of FloatVector
below).
This is the @(@
n
@)@ by
n
matrix that
we are computing the determinant of
and that defines the linear equation.
B
has the prototype
const FloatVector &B
and the size of
B
must equal @(@
n * m
@)@
(see description of FloatVector
below).
This is the @(@
n
@)@ by
m
matrix that
defines the right hand side of the linear equations.
If
m
is zero,
B
is not used.
X
has the prototype
FloatVector &X
and the size of
X
must equal @(@
n * m
@)@
(see description of FloatVector
below).
The input value of
X
does not matter.
On output, the elements of
X
contain the solution
of the equation we wish to solve
(unless
signdet
is equal to zero).
If
m
is zero,
X
is not used.
logdet
has prototype
Float &logdet
On input, the value of
logdet
does not matter.
On output, it has been set to the
log of the determinant of
A
(but not quite).
To be more specific,
the determinant of
A
is given by the formula
det = signdet * exp( logdet )
This enables LuSolve
to use logs of absolute values
in the case where
Float
corresponds to a real number.
Float
must satisfy the conditions
for a NumericType
type.
The routine CheckNumericType
will generate an error message
if this is not the case.
In addition, the following operations must be defined for any pair
of
Float
objects
x
and
y
:
Operation  Description 
log(x)

returns the logarithm of
x
as a
Float
object

FloatVector
must be a SimpleVector
class with
elements of type Float
.
The routine CheckSimpleVector
will generate an error message
if this is not the case.
lu_solve.hpp
defines the template function
template <typename Float>
bool LeqZero<Float>(const Float &x)
in the CppAD
namespace.
This function returns true if
x
is less than or equal to zero
and false otherwise.
It is used by LuSolve
to avoid taking the log of
zero (or a negative number if
Float
corresponds to real numbers).
This template function definition assumes that the operator
<=
is defined for
Float
objects.
If this operator is not defined for your use of
Float
,
you will need to specialize this template so that it works for your
use of LuSolve
.
Complex numbers do not have the operation or <=
defined.
In addition, in the complex case,
one can take the log of a negative number.
The specializations
bool LeqZero< std::complex<float> > (const std::complex<float> &x)
bool LeqZero< std::complex<double> >(const std::complex<double> &x)
are defined by including lu_solve.hpp
.
These return true if
x
is zero and false otherwise.
lu_solve.hpp
defines the template function
template <typename Float>
bool AbsGeq<Float>(const Float &x, const Float &y)
If the type
Float
does not support the <=
operation
and it is not std::complex<float>
or std::complex<double>
,
see the documentation for AbsGeq
in LuFactor
.