Division of matrix with complex numbers

I have Hermitian matrix which is generated from Z=HH' where its diagonal elements consist of real numbers. Then, from the diagonal elements, I would like to put it into a diagonal matrix. Finally, I would like to calculate 1 divide by each of the diagonal elements of this matrix.However, there is an error which states that "no matches '/' with these operands". My codes are as written below:

#include<iostream>
#include <complex>
using namespace std;


//Main function
//All the operations is done here
int main()
{
complex <double> theta[10][10];
int order = 2;
int i, j;

//Z is assumed to be Hermitian Positive Definite where
the diagonal elements are real numbers

complex <double> Z[2][2] = { { 18.44 + 0i, -4.2 - 3.8i },
{ -4.2 - 3.8i, 7.8 + 0i} };

for (i = 0; i < order; i++)
{
for (j = 0; j < order; j++)
{
if (i == j)
{
theta[i][j] = 1 / Z[i][j];
}
else
theta[i][j] = 0;
cout << "theta [" << i << "][" << j << "]" << theta[i][j] << " "
<< endl;
}
}

cout << "\n";
system("pause");
return 0;
}
The divide operation in theta[i][j] = 1 / Z[i][j]; is of the form
int / complex<double>
and isn't defined. That 1 will be taken as an int constant if it has no decimal point.

Make it
double/complex<double>
simply by changing the 1 in that division to 1.0. i.e. add the decimal point:
theta[i][j] = 1.0 / Z[i][j];


Your matrix Z isn't Hermitian, BTW. The corresponding off-diagonal elements need to be complex conjugates, not the same as each other.
Last edited on
Thank you for your feedback lastchance...yes ..you are correct...z is a hermitian matrix if we have a matrix like this :
z[i][j] = { { 18.44 + 0i, -4.2 - 3.8i },
{ -4.2 + 3.8i, 7.8 + 0i} };
Topic archived. No new replies allowed.