943,640 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 10290
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Apr 5th, 2009
0

Re: Matrix Multiplication using Multi-Dimensional Arrays

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.

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 85
Solved Threads: 42
Nearly a Posting Virtuoso
vishesh is offline Offline
1,362 posts
since Oct 2006
Apr 5th, 2009
0

Re: Matrix Multiplication using Multi-Dimensional Arrays

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.
Reputation Points: 7
Solved Threads: 0
Light Poster
ARYT is offline Offline
38 posts
since Feb 2009
Apr 5th, 2009
0

Re: Matrix Multiplication using Multi-Dimensional Arrays

Oops...I just missed a point in previous post. Anyway the loop gotta look like this.

cpp Syntax (Toggle Plain Text)
  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.
Reputation Points: 85
Solved Threads: 42
Nearly a Posting Virtuoso
vishesh is offline Offline
1,362 posts
since Oct 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: solution for 3 programs
Next Thread in C++ Forum Timeline: Implementing Linked List iterator, gcc is acting wierd





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC