19template <
int Rows,
int Cols,
typename F>
21 constexpr double kEpsilon = 1e-5;
26 for (
int i = 0; i < Cols; ++i) {
28 dX_plus(i) += kEpsilon;
30 dX_minus(i) -= kEpsilon;
31 result.col(i) = (f(dX_plus) - f(dX_minus)) / (kEpsilon * 2.0);
45 constexpr double kEpsilon = 1e-5;
46 Eigen::MatrixXd result;
49 for (
int i = 0; i < x.rows(); ++i) {
50 Eigen::VectorXd dX_plus = x;
51 dX_plus(i) += kEpsilon;
52 Eigen::VectorXd dX_minus = x;
53 dX_minus(i) -= kEpsilon;
54 Eigen::VectorXd partialDerivative =
55 (f(dX_plus) - f(dX_minus)) / (kEpsilon * 2.0);
57 result.resize(partialDerivative.rows(), x.rows());
60 result.col(i) = partialDerivative;
79template <
int Rows,
int States,
int Inputs,
typename F,
typename... Args>
96template <
typename F,
typename... Args>
98 const Eigen::VectorXd& u, Args&&... args) {
100 [&](
const Eigen::VectorXd& x) {
return f(x, u, args...); }, x);
116template <
int Rows,
int States,
int Inputs,
typename F,
typename... Args>
133template <
typename F,
typename... Args>
135 const Eigen::VectorXd& u, Args&&... args) {
137 [&](
const Eigen::VectorXd& u) {
return f(x, u, args...); }, u);
Definition LinearSystem.hpp:20
auto NumericalJacobianU(F &&f, const Vectord< States > &x, const Vectord< Inputs > &u, Args &&... args)
Returns numerical Jacobian with respect to u for f(x, u, ...).
Definition NumericalJacobian.hpp:117
auto NumericalJacobian(F &&f, const Vectord< Cols > &x)
Returns numerical Jacobian with respect to x for f(x).
Definition NumericalJacobian.hpp:20
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.hpp:21
auto NumericalJacobianX(F &&f, const Vectord< States > &x, const Vectord< Inputs > &u, Args &&... args)
Returns numerical Jacobian with respect to x for f(x, u, ...).
Definition NumericalJacobian.hpp:80
Eigen::Vector< double, Size > Vectord
Definition EigenCore.hpp:12