how to multiply 2 matrices

This is a discussion on how to multiply 2 matrices within the C Programming forums, part of the General Programming Boards category; Hi all, I've to multiply 2 matrices together, As you know, for example , an ( A by B matrix ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    13

    how to multiply 2 matrices

    Hi all,
    I've to multiply 2 matrices together, As you know, for example , an ( A by B matrix multiplied by a C by D matrix will return a A by D matrix. Condition is that B = C . How do we define each matrix? maybe an A by B matrix is like this: A by B matrix: ( 1 3 2 )
    ( 2 2 3 ). So this 2( rows) by 3( columns) matrix is going to be multiplied by another matrix.

    What I can think of so far is :

    Start with the first row of the first matrix . The first element of the first row is multiplied by the first element of the first column of the second matrix, second to second.. third to third.. and the total sum stored will be the addition of these results. They'll be stored in the First row and first column of the answer matrix. Then I carry on till i get the answer. Anyone have any ideas on how to do this, especially when the user should be able to define any matrix he likes( up to a certain limit).

    THANKS !

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > maybe an A by B matrix is like this: A by B matrix: ( 1 3 2 )
    ( 2 2 3 ).
    This would be
    Code:
    int matrix_ab[2][3] = {
       { 1, 3, 2 },
       { 2, 2, 3 },
    };
    > especially when the user should be able to define any matrix he likes( up to a certain limit)
    Well if the limit is say 10, then
    int matrix_ab[10][10];
    int matrix_cd[10][10];
    int matrix_result[10][10];

    The rest is input and loops.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C simple Matrices
    By Cyberman86 in forum C Programming
    Replies: 3
    Last Post: 05-07-2009, 05:20 PM
  2. adding matrices, help with switches
    By quiet_forever in forum C++ Programming
    Replies: 7
    Last Post: 09-04-2007, 08:21 AM
  3. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-13-2004, 11:19 PM
  4. Very handy matrix functions - part 1
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 05-20-2004, 10:38 AM
  5. Problem multiplying rotation matrices together
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-04-2003, 08:20 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21