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);
46 constexpr double kEpsilon = 1e-5;
47 Eigen::MatrixXd result;
50 for (
int i = 0; i < x.rows(); ++i) {
51 Eigen::VectorXd dX_plus = x;
52 dX_plus(i) += kEpsilon;
53 Eigen::VectorXd dX_minus = x;
54 dX_minus(i) -= kEpsilon;
55 Eigen::VectorXd partialDerivative =
56 (f(dX_plus) - f(dX_minus)) / (kEpsilon * 2.0);
58 result.resize(partialDerivative.rows(), x.rows());
61 result.col(i) = partialDerivative;
80template <
int Rows,
int States,
int Inputs,
typename F,
typename... Args>
97template <
typename F,
typename... Args>
99 const Eigen::VectorXd& u, Args&&... args) {
101 [&](
const Eigen::VectorXd& x) {
return f(x, u, args...); }, x);
117template <
int Rows,
int States,
int Inputs,
typename F,
typename... Args>
134template <
typename F,
typename... Args>
136 const Eigen::VectorXd& u, Args&&... args) {
138 [&](
const Eigen::VectorXd& u) {
return f(x, u, args...); }, u);
Definition SystemServer.h:9
auto NumericalJacobian(F &&f, const Vectord< Cols > &x)
Returns numerical Jacobian with respect to x for f(x).
Definition NumericalJacobian.h:20
Eigen::Matrix< double, Rows, Cols, Options, MaxRows, MaxCols > Matrixd
Definition EigenCore.h:21
Eigen::Vector< double, Size > Vectord
Definition EigenCore.h:12
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.h:118
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.h:81