duggi
duggi

Reputation: 566

In EIGEN c++ cannot multiply vector by it's transpose

While executing the below code I'm getting this error: "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;
}

Is there any other way of doing this without the compiler complaining ?

Upvotes: 1

Views: 4235

Answers (1)

Avi Ginsburg
Avi Ginsburg

Reputation: 10596

Vector3d is defined as a column vector, hence both v and vT are column vectors. Therefore, the operation v*vT doesn't make sense. What you want to do is

Matrix3d ans = v*v.transpose();

or define vT as a RowVector3d

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

Upvotes: 6

Related Questions