Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Matrix Multiplication (http://www.go4expert.com/forums/matrix-multiplication-t13729/)

abhi 11Sep2008 16:52

Matrix Multiplication
pls let me know the logic for multiplying a matrix...i have been racking my brains on that

aortizb 13Sep2008 00:20

Re: Matrix Multiplication
please could you elaborate your question?

xpi0t0s 13Sep2008 03:37

Re: Matrix Multiplication
Multiplying by a constant or multiplying two matrices?
If the former then it's just a case of multiplying each element by that number. a{p,q,r} = {ap,aq,ar}.
Multiplying two matrices is more involved, first you must check that the number of columns in the first equals the number of rows in the second, then:
[a0 a1] [b0 b1 b2] = [a0b0+a1b3 a0b1+a1b4 a0b2+a1b5 ]
[a2 a3] [b3 b4 b5] [a2b0+a3b3 a2b1+a2b4 a2b2+a3b5 ]

Is it the maths you're stuck on or the implementation?

abhi 13Sep2008 12:54

Re: Matrix Multiplication
i want the source code not the math behind it.... how to implement it using the concepts of loops and arrays only?

xpi0t0s 13Sep2008 13:05

Re: Matrix Multiplication
It's not difficult, where are you stuck? If I give you two matrices, e.g.
[ 1 2 ] [ 5 6 7 ]
[ 3 4 ] [ 8 9 0 ]

how far do you get with "write a program to multiply them"? Do you at least get a main function?
Obviously you'll need some way to represent the matrices, you're correct to use arrays, that's exactly what they're designed for, and you're not going to be able to do this generically without some kind of loop.
Have you figured out how to store the matrices in the arrays yet?

abhi 13Sep2008 13:19

Re: Matrix Multiplication
yes i do,
i have taken the two input matrix matrix declared as a[3][3] b[3][3] using loop
n use 3 for loops,one inside other
i,j,k,initiated thm at zero, & i<=2,j<=2, k<=0
n used
is it correct?

xpi0t0s 14Sep2008 14:40

Re: Matrix Multiplication
Could you post the actual code rather than a description? I don't see the point of what appears from the description to be for (k=0; k<=0; k++). From that I'd say no for "is it correct", but presumably you either get the right or wong answer, if you get the wrong answer then it's clearly not correct.

All times are GMT +5.5. The time now is 07:38.