如何解决本征自然对数函数的问题:“未定义模板的隐式实例化”
我正在进行一个化学仿真,该仿真使用Eigen进行涉及线性代数的计算。
在给定当前底物浓度矢量的情况下,这是我确定吉布斯自由能产量的代码:
#define R 8.314 // Gas constant - J mol^-1 K^-1
#define T 298.0 // Temperature - K
typedef Eigen::MatrixXf Matrix;
typedef Eigen::VectorXf Vector;
Vector calculateGibbs(Vector C,Matrix S,Vector F) {
/** Calculate value of G vector based on current
concentration vector C,stoichiometric matrix S,temperature T,and standard ∆G˚ vector F.
Formula Used: G = S^t * (F + RT ln C)
Where R is the universal gas constant (see line 16),and S^t is the transpose of S.
*/
double RT = R * T;
return S.transpose() * (F + RT * C.log());
}
当我尝试编译调用此函数的代码时,出现以下错误:
error: implicit instantiation of
undefined template 'Eigen::MatrixLogarithmReturnValue<Eigen::Matrix<float,-1,1,1> >'
return S.transpose() * (F + RT * C.log());
^
/usr/local/include/eigen3/Eigen/src/Core/util/ForwardDeclarations.h:287:34: note:
template is declared here
template<typename Derived> class MatrixLogarithmReturnValue
不确定我在做什么错。这是我引用的自然对数函数的文档:https://eigen.tuxfamily.org/dox/group__CoeffwiseMathFunctions.html。
任何人都可以澄清我在做什么吗?任何帮助将不胜感激。
编辑:要明确一点,我的目标是弄清楚如何使用本征框架获取向量的自然对数。
解决方法
大多数Eigen的系数运算,包括.log()
,refer to Array objects。按系数的对数运算不能应用于示例中使用的Matrix
类型(或Vector
typedef,这只是Matrix
的特例)。
使用.array()
和.matrix()
可以在类型之间进行切换。在您的情况下,返回值可能是:
return S.transpose() * (F.array() + RT * C.array().log()).matrix();
或等效地
return S.transpose() * (F + RT * C.array().log().matrix());
,
这是解决方案!
A better way to make matrix - log operations in Eigen?
我需要将C向量转换为数组,调用log方法,然后将其转换回矩阵!最后,矢量加法仍然有效,因为在本征矢量中,矢量是矩阵的子类(与numpy不同,它区分N维数组和1xN维数组)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。