Thread: 2 Matrices multiply problem

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    9

    2 Matrices multiply problem

    Hello there,
    I have a struct of matrix that is defined like this:
    Code:
      typedef struct {
              int rows;
              int cols;
              int *mat;
           } Matrix;
    And I have 2 pointers to matrices m1 and m2 and I would like to multiply between them.

    Now, given the fact that each matrix is saved in a 1-dimensional array, how can I multiply it properly in the result matrix, m3?
    Any ideas?

    Thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > Now, given the fact that each matrix is saved in a 1-dimensional array, how can I multiply it properly in the result matrix, m3?
    Well you've got rows and cols members, which I guess you've used before (say in assigning the matrix values to begin with).
    So you should be able to extract any given mat[row][col] value.

    Knowing how to do this, the standard matrix multiply algorithm (see wikipedia or mathworld) should see you home.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Matrices
    By elleshlar in forum C Programming
    Replies: 2
    Last Post: 05-07-2011, 03:33 AM
  2. Replies: 15
    Last Post: 01-24-2008, 09:40 PM
  3. Nasty linker problem; multiply defined
    By cboard_member in forum C++ Programming
    Replies: 4
    Last Post: 09-02-2005, 03:06 PM
  4. Problem with multiply defined objects
    By Tostado in forum C++ Programming
    Replies: 2
    Last Post: 05-03-2004, 05:05 PM
  5. how to multiply 2 matrices
    By newguy in forum C Programming
    Replies: 1
    Last Post: 10-29-2001, 03:48 AM