Dear all,
Im trying to do a matrix multiplication with complex number. I have 2 structures:
/* Structures */
typedef struct complex { // Complex structure = real and imaginary part.
double re;
double im;
} Complex;
typedef struct complex_matrix {
int rows;
int cols;
Complex **mat;
} Complex_Matrix;
I then try do to my complex matrix multiplication, but in "sum" it gives me an error that says I can't use sum that way. Maybe I need to define sum as a Complex_Matrix as well? Or how do I solve this?
Here is my complex matrix multiplication C code:
Complex_Matrix complex_multiply(Complex_Matrix a, Complex_Matrix b){
Complex_Matrix m;
int i,j,k;
float sum;
m = complex_allocate(a.rows, a.cols);
for (i=0; i<a.rows; i++) {
printf("\n");
for (j=0; j<b.cols; j++) { // columns
for (k=0; k<a.cols; k++) { // k=a.cols or b.rows.
sum += multiplication(a.mat[i][k], b.mat[k][j]);
}
m.mat[i][j] = sum; // puts the sum in matrix array.
}
}
return m;
}
Where multiplication is:
Complex multiplication(Complex x, Complex y){ // multiply the two inputs together.
Complex z;
z.re = (x.re*y.re) - (x.im*y.im);
z.im = (x.re*y.im)+(x.im*y.re);
return z;
}
Thank you guys so much!