Matrix Multiplication using Multi-Dimensional Arrays

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Matrix Multiplication using Multi-Dimensional Arrays

 
0
  #11
Apr 5th, 2009
First of all replace M[i][j] = m1[i][k]*m2[k][j]; with M[i][j] += m1[i][k]*m2[k][j]; . See the algorithm in above post, for explanation. Also dont forget to set M[i][j] value to 0 before running third loop.

  1. infile >> m1[i][j] >> m2[i][j];
  2. M[i][j] += m1[i][k]*m2[k][j];

Here in second line you are multiplying two array members which haven't got their value yet. You're taking values for different cells. Better take inputs earlier than start multiplying matrices or take it like infile >> m1[i][k] >> m2[k][j] but wouldnt it be a bit awkward
Last edited by vishesh; Apr 5th, 2009 at 5:18 am.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 38
Reputation: ARYT is an unknown quantity at this point 
Solved Threads: 0
ARYT's Avatar
ARYT ARYT is offline Offline
Light Poster

Re: Matrix Multiplication using Multi-Dimensional Arrays

 
0
  #12
Apr 5th, 2009
Well, thanks but I think k shouldn't have a value. It’s basically 0 and later it's used for increment only.
I've also added that += and your infile method, but no difference.
Religion is a way of austerity and a mental self-tranquilizer which is associated with numerous cultures. One cannot deny that Moses predominate Jewish over other believers, while Mohammad calls Muslims to be the ones who excel in humanity and still they are the messengers sent from one God, postulating the impacts of religion and ideology on genetics?
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,311
Reputation: vishesh is on a distinguished road 
Solved Threads: 36
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Matrix Multiplication using Multi-Dimensional Arrays

 
0
  #13
Apr 5th, 2009
Oops...I just missed a point in previous post. Anyway the loop gotta look like this.

  1. //take matrices values before starting
  2. for (int i=0; i<6; i++)
  3. {
  4. for (int j=0; j<6; j++)
  5. {
  6. M[i][j] = 0;
  7. for (int k=0; k<6; k++)
  8. {
  9. M[i][j] += m1[i][k] * m2[k][j];
  10. }
  11. cout << M[i][j] << " "; // this is what i missed to tell
  12. }
  13. cout<<endl;
  14. }

> your infile method
That method I dont suggest. Take matrices values rows by rows only, so that there isnt any confusion.
Last edited by vishesh; Apr 5th, 2009 at 11:32 am.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC