Hi, I would like to calculate the average of the diagonal elements of a matrix. May I know which part that I need to do a correction? I have no idea why the division operation to compute average is not match.
One more thing, may I know why I cannot use all the buttons at the bottom of this box? I tried to insert the code using the <> button, but it failed.
//Main function
//All the operations is done here
int main(int argc, char** argv)
{
int order = 4;
int i, j;
complex <double> average= (0.0, 0.0);;
complex <double> d1sum = (0.0,0.0);
//complex <double> d2sum = (0.0, 0.0);
first, did you really just do an order*order loop to do one row's worth of work?
for(i = 0; i< order; i++)
sum += m[i][i];
I think you just need
complex<double> den(order,0.0);
average = d1sum/den;
or some sort of cast may make it work. Though I would have thought it knew how to divide complex by int... not sure ... try that to see if it works?