Matrix Multiplication

Hi there!

I was wondering if you could please look this over real quickly and see if there's a small error that I am missing. I am multiplying an 8x13 matrix by an 8x8 identity matrix. The outputs are all correct except all of column 8 if you start counting with zero. It puts out zeros instead of the correct answers.

H is a matrix. The first function merely finds the transpose of the matrix- HT.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
double H[13][8]={2.0000,-2.0000,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,-1.0000,0.0,0.0,0.0,0.0,0.0,1.1111,0.0,0.0,-1.1111,0.0,0.0,0.0,0.0,0.0,1.3333,0.0,0.0,-1.3333,0.0,0.0,0.0,0.0,0.0,1.1111,-1.1111,0.0,0.0,0.0,0.0,4.1111,-2.0000,0.0,-1.1111,0.0,0.0,0.0,0.0,-2.0000,3.3333,0.0,0.0,-1.3333,0.0,0.0,0.0,0.0,0.0,3.3611,-1.1111,0.0,-1.2500,0.0,0.0,-1.1111,0.0,-1.1111,5.5556,-2.0000,0.0,-1.3333,0.0,0.0,-1.3333,0.0,-2.0000,4.3333,0.0,0.0,-1.0000,0.0,0.0,-1.2500,0.0,0.0,2.6786,-1.4286,0.0,0.0,0.0,0.0,-1.3333,0.0,-1.4286,4.4286,-1.6667,0.0,0.0,0.0,0.0,-1.0000,0.0,-1.6667,2.6667};
double HT[8][13];
double invR[8][8]={1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,1.0};
double mult[8][13];
int i,j;

int main() {
 
for(i=0;i<8;i++){
    pc.printf("\n\r");
    for(j=0;j<13;j++){
        HT[i][j]=H[j][i];
        pc.printf("%f   ",HT[i][j]);
        }
    }


for(int x=0;x<8;x++){ 
    pc.printf("\r\n");
    for(int y=0;y<13;y++){ 
        mult[x][y]=0;
        for(int z=0;z<8;z++){ 
            mult[x][y]+=HT[x][y]*invR[z][y];
        }
        pc.printf("%f   ",mult[x][y]);
    }

}

}


Thank you!


Note: I am compiling this in an mbed compiler to put on a microcontroller.
Edit: I figured it out myself. It had to do with switching the matrices. Thank you very much anyway!
Last edited on
Topic archived. No new replies allowed.