将 cmath 函数与 get_continuous_state_vector() 元素一起使用时没有匹配函数



在我的DoCalcTimeDerivative中,我需要取 cos 作为状态向量元素之一。

我使用以下代码执行此操作

Vector4<T> x = context.get_continuous_state_vector().CopyToVector();
T c0 = std::cos(x[0]);

但是,我收到以下错误

error: no matching function for call to ‘cos(Eigen::DenseCoeffsBase<Eigen::Matrix<Eigen::AutoDiffScalar<Eigen::Matrix<double, -1, 1> >, 4, 1, 0, 4, 1>, 1>::Scalar&)’

我也尝试过使用

const systems::VectorBase<T>& x = context.get_continuous_state_vector();
T c0 = std::cos(x[0]);

这同样会给出以下错误

error: no matching function for call to ‘cos(const Eigen::AutoDiffScalar<Eigen::Matrix<double, -1, 1> >&)’

这很奇怪,因为我看到示例中使用了std::cosstd::sin,但我似乎无法弄清楚为什么它在示例中有效,而不是我的。

试试这个:

using std::cos;
Vector4<T> x = context.get_continuous_state_vector().CopyToVector();
T c0 = cos(x[0]);

最新更新