1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Matrix Multiplication

Discussion in 'C' started by abhi, Sep 11, 2008.

  1. abhi

    abhi New Member

    Joined:
    Aug 30, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    pls let me know the logic for multiplying a matrix...i have been racking my brains on that
     
  2. aortizb

    aortizb New Member

    Joined:
    Sep 12, 2008
    Messages:
    32
    Likes Received:
    0
    Trophy Points:
    0
    please could you elaborate your question?
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     
  4. abhi

    abhi New Member

    Joined:
    Aug 30, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    i want the source code not the math behind it.... how to implement it using the concepts of loops and arrays only?
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     
  6. abhi

    abhi New Member

    Joined:
    Aug 30, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
    C[j]=c[j]+a[j]*b[j][k]
    is it correct?
     
  7. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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.
     

Share This Page