| | |
Matrix Multiplication using Multi-Dimensional Arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
First of all replace
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
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)
infile >> m1[i][j] >> m2[i][j]; 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.
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.
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?
Oops...I just missed a point in previous post. Anyway the loop gotta look like this.
> your infile method
That method I dont suggest. Take matrices values rows by rows only, so that there isnt any confusion.
cpp Syntax (Toggle Plain Text)
//take matrices values before starting for (int i=0; i<6; i++) { for (int j=0; j<6; j++) { M[i][j] = 0; for (int k=0; k<6; k++) { M[i][j] += m1[i][k] * m2[k][j]; } cout << M[i][j] << " "; // this is what i missed to tell } cout<<endl; }
> 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.
![]() |
Similar Threads
Other Threads in the C++ Forum
- Previous Thread: solution for 3 programs
- Next Thread: Implementing Linked List iterator, gcc is acting wierd
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






