This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Incompatibility of square matrix with vector.asDiagonal

Tags: None
(comma "," separated)
antonyjoseph
Registered Member
Posts
1
Karma
0
I am new to eigen. Could you tell me why the following piece of code gives an error?
Code: Select all
#include <Eigen/Dense>
#include <iostream>
#include <cmath>
#include <Eigen/Core>

using namespace Eigen;
using namespace std;

int main(){
   int nStates = 5;
   MatrixXd B = MatrixXd::Random(5,5);
   VectorXd ss(nStates);
   ss << 22,123,123,123,1211;
   MatrixXd bb = ss.asDiagonal();
   cout<< B + ss.asDiagonal() ;

}


Here is the error I got
[bug] error: invalid operands to binary expression ('MatrixXd' (aka 'Matrix<double, Dynamic, Dynamic>') and 'const DiagonalWrapper<const Eigen::Matrix<double, -1, 1, 0, -1, 1> >')
cout<< B + ss.asDiagonal() ;
~ ^ ~~~~~~~~~~~~~~~[/bug]

However when I replace the
Code: Select all
cout << BB + ss.asDiagonal()

by
Code: Select all
cout << BB + bb

it works.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is a non supported operation. You can only combine dense and diagonal matrices trough products or compound assignments:

B += bb.asDiagonal();
B -= bb.asDiagonal();


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]