Multi Dimensional Array Multiplication Failure

Hi there!

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

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
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++){    //rows in 1
    pc.printf("\r\n");
    for(int y=0;y<13;y++){ //columns in 2
        mult[x][y]=0;
        for(int z=0;z<8;z++){ //rows in 1
            mult[x][y]+=HT[x][y]*invR[z][y];
        }
        pc.printf("%f   ",mult[x][y]);
    }

}


Thank you!
Last edited on
double H[13][8] creates an array 13x8 or 13 arrays with 8 blocks (okay, that may be the worst description ever, maybe even inaccurate, but it almost gets the point accross).

To create and define a multi-dimensional array is similar to as follows:

 
int myarr [2][3] = { {1, 2, 3}, {4, 5, 6} }; //creates an array 2x3 or 2 arrays, 3 blocks long 


Notice hhow each level of the array is contained within it's own set of {curly braces} and that each level is seperated by a comma (,). All of which is contained with an outer set of braces capped off with the all important semi-colon (;).

You have the declaration backwards, you define a 13x8 array and use your for statement to display an 8x13 array.

Your arrays are all defined using the syntax for a single-dimensional array.

Look at the following section of this site's tutorial for arrays and multi-dimensional arrays:

http://cplusplus.com/doc/tutorial/arrays/

You are also missing the return statement and a } at the very end of your main function (unless there is more that follows what you have provided, in which case never mind but if this is all you have, then you also need the #include s).
Topic archived. No new replies allowed.