Element-wise multiplication using Eiegn

I am trying to perform an element-wise multiplication of a row vector with matrix. In MATLAB this would be simply done by the "dot" operator or:

 
  data_deriv  = 1i * k .* fk;

where k is row vector and fk is a matrix.
Now in C++ I have this code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Matrix <double, 1, nx> eKX; 
eKX.setZero();

for(int i = 0; i < nx; i++){
			eKX[i] = //some expression
	}
for (int i = 0; i < nx; i++){
		for (int j = 0; j < ny+1; j++){ 
			for (int k = 0; k < ncomp; k++){
				uhkOutX[i*(ny+1)+j][k] = //FFT of some expression 
			}
		}
	}

Eigen::Map<Eigen::MatrixXcd, Eigen::Unaligned> euhX(reinterpret_cast<std::complex<double>*>(uhkOutX),(ny+1),nx); //(nyk),nx);

Now, I am trying to take the product of eKX which is a row vector of 1 x 10 and the matrix euhX of a 11 x 10. I tried few things, none of which seem to work really:
 
eduxk = 1i * eKX.array() * euhX.array() ; //ERROR 



static assertion failed: YOU_MIXED_MATRICES_OF_DIFFERENT_SIZES

Last edited on
I was able to solve this issue with replacing the last line with:

1
2
eduxk = euhX * (eKX * 1i).asDiagonal();

Topic archived. No new replies allowed.