468,512 Members | 1,423 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

matrix multiplication (1d to 2d mapping) lost!!!

16
hello,
i have 2 upper triangular matrices A and B.. the values are stored in efficient format in the text file. I wanted to use those values for matrix multiplication and display the result C on the screen.
I am supposed to use 1d arrays. SO, basically i have 2 --> 1d arrays which i am supposed to multiply to get C[i].C[i] must not store zeroes(i.e it must also be in efficient format).

I am having trouble in the multiplication part... i am getting answers totally out of range for C[i].
int i,j,k,m=0,n=0;
for(i=row;i>0;i--){
for(j=m;j<sum;j++){
for(k=0;k<=j;k++){
matC[j] += matA[k]*matB[j];

}

} m++;
printf("\n");
}
/**** 'sum' is the total slots in the C[i] array****/
I am having trouble developing the equation to put within the for loop.
for ex: A[i]={1,2,3,4,5,6} /*efficient format*/
B[i]={1,2,3,4,5,6}
I need to calculate
C[i] ={ }... i am stuck.. i hope the question is clear
any help would be great.
thanks in advance
Oct 9 '06 #1
1 3800
D_C
293 100+
I have some code that treats a 1D upper triangular matrix as 2D. I'll post the relevant parts of that code, and hopefully it will help you. Originally, the code was to find N x N symmetric matrices with a zero diagonal, such that each row and column summed to the same value. When N = 5, the matrix took the form
Expand|Select|Wrap|Line Numbers
  1. 0 A B C D
  2. A 0 E F G
  3. B E 0 H I
  4. C F H 0 J
  5. D G I J 0
Only the upper triangular half was stored, or A - J, was stored.

Notice that each diagonal entry is 0, and not necessary. That's why for N = 5, there are only 1+2+3+4 = N(N-1) / 2 = 10 entries instead of 1+2+3+4+5 = N(N+1) / 2 = 15 entries. If you need 15 entries, possibly just change N-1 to N each time in int row(int) and int col(int).

Expand|Select|Wrap|Line Numbers
  1. static const int LENGTH = (N*(N-1))/2; 
  2. int col(int c) // 0=>(0,1), N-1=>(0,N), and LENGTH=>(N,N)
  3. {              
  4.   int dim = N-1; 
  5.   int add = 1;
  6.   while(c >= dim)
  7.   {
  8.     c -= dim;
  9.     dim--;
  10.     add++;
  11.   }
  12.   return c+add;
  13. }
  14.  
  15. int row(int c)
  16. {
  17.   int dim = N-1;
  18.   int add = 0;
  19.   while(c >= dim)
  20.   {
  21.     c -= dim;
  22.     dim--;
  23.     add++;
  24.   }
  25.   return add;
  26. }
Oct 9 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

11 posts views Thread by Michael Bader | last post: by
14 posts views Thread by amitnanda | last post: by
7 posts views Thread by VijaKhara | last post: by
6 posts views Thread by amitsoni.1984 | last post: by
1 post views Thread by Sozos | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.