gpt4 book ai didi

c++ - 在 EIGEN 中,c++ 不能将 vector 乘以它的转置

转载 作者:行者123 更新时间:2023-11-30 01:13:20 26 4
gpt4 key购买 nike

在执行以下代码时,我收到此错误:“INVALID_VECTOR_VECTOR_PRODUCT__IF_YOU_WANTED_A_DOT_OR_COEFF_WISE_PRODUCT_YOU_MUST_USE_THE_EXPLICIT_FUNCTIONS”

#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
Vector3d v(1, 2, 3);
Vector3d vT = v.transpose();
Matrix3d ans = v*vT;
std::cout << ans << std::endl;
}

还有没有编译器提示的其他方法吗?

最佳答案

Vector3d 被定义为列 vector ,因此 vvT 都是列 vector 。因此,操作 v*vT 没有意义。你要做的是

Matrix3d ans = v*v.transpose();

或将 vT 定义为 RowVector3d

Vector3d v(1, 2, 3);
RowVector3d vT = v.transpose();
Matrix3d ans = v*vT;

关于c++ - 在 EIGEN 中,c++ 不能将 vector 乘以它的转置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32440048/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com