8 #include <cppad/cg.hpp> 9 #include <cppad/cppad.hpp> 10 #include <cppad/example/cppad_eigen.hpp> 22 typedef CppAD::AD<CppAD::cg::CG<double>>
Scalar;
24 inline static Scalar
sin(
const Scalar& x) {
return CppAD::sin(x); }
25 inline static Scalar
cos(
const Scalar& x) {
return CppAD::cos(x); }
26 inline static Scalar
tan(
const Scalar& x) {
return CppAD::tan(x); }
27 inline static Scalar
sinh(
const Scalar& x) {
return CppAD::sinh(x); }
28 inline static Scalar
cosh(
const Scalar& x) {
return CppAD::cosh(x); }
29 inline static Scalar
tanh(
const Scalar& x) {
return CppAD::tanh(x); }
30 inline static Scalar
exp(
const Scalar& x) {
return CppAD::exp(x); }
31 inline static Scalar
fabs(
const Scalar& x) {
return CppAD::fabs(x); }
32 inline static Scalar
sqrt(
const Scalar& x) {
return CppAD::sqrt(x); }
35 inline static Eigen::Matrix<Scalar, Dims, 1>
solve(
const Eigen::Matrix<Scalar, Dims, Dims>& A,
36 const Eigen::Matrix<Scalar, Dims, 1>& b)
38 Eigen::Matrix<Scalar, Dims, Dims> LU;
41 Eigen::Matrix<Scalar, Dims, 1> out;
42 solveCrout(LU, b, out);
50 template <
typename T,
int rowAndCol>
51 void static Crout(
const Eigen::Matrix<T, rowAndCol, rowAndCol>& S, Eigen::Matrix<T, rowAndCol, rowAndCol>& D)
53 for (
int k = 0; k < S.rows(); ++k)
55 for (
int i = k;
i < S.rows(); ++
i)
58 for (
int p = 0; p < k; ++p)
59 sum += D(
i, p) * D(p, k);
60 D(
i, k) = S(
i, k) - sum;
62 for (
int j = k + 1; j < S.rows(); ++j)
65 for (
int p = 0; p < k; ++p)
66 sum += D(k, p) * D(p, j);
67 D(k, j) = (S(k, j) - sum) / D(k, k);
73 template <
typename T,
int rowAndCol>
74 void static solveCrout(
const Eigen::Matrix<T, rowAndCol, rowAndCol>& LU,
75 const Eigen::Matrix<T, rowAndCol, 1>& b,
76 Eigen::Matrix<T, rowAndCol, 1>&
x)
78 const int d = rowAndCol;
80 for (
int i = 0;
i < d; ++
i)
83 for (
int k = 0; k <
i; ++k)
84 sum += LU(i, k) * y[k];
85 y[i] = (b(i) - sum) / LU(i, i);
87 for (
int i = d - 1;
i >= 0; --
i)
90 for (
int k =
i + 1; k < d; ++k)
91 sum += LU(
i, k) * x(k);
static Scalar sinh(const Scalar &x)
Definition: CppADCodegenTrait.h:27
static Scalar sin(const Scalar &x)
Definition: CppADCodegenTrait.h:24
static Scalar tanh(const Scalar &x)
Definition: CppADCodegenTrait.h:29
static Scalar cosh(const Scalar &x)
Definition: CppADCodegenTrait.h:28
Trait defining basic math functions for CppAD CodeGen Auto-Diff types.
Definition: CppADCodegenTrait.h:19
static Scalar cos(const Scalar &x)
Definition: CppADCodegenTrait.h:25
ct::core::StateVector< state_dim > x
static Scalar exp(const Scalar &x)
Definition: CppADCodegenTrait.h:30
static Scalar sqrt(const Scalar &x)
Definition: CppADCodegenTrait.h:32
static Scalar fabs(const Scalar &x)
Definition: CppADCodegenTrait.h:31
static Eigen::Matrix< Scalar, Dims, 1 > solve(const Eigen::Matrix< Scalar, Dims, Dims > &A, const Eigen::Matrix< Scalar, Dims, 1 > &b)
Solves a linear system of equations using an LU factorization.
Definition: CppADCodegenTrait.h:35
CppAD::AD< CppAD::cg::CG< double > > Scalar
Definition: CppADCodegenTrait.h:22
static Scalar tan(const Scalar &x)
Definition: CppADCodegenTrait.h:26