Thread: Pruduct of matrixes

  1. #1
    Registered User
    Join Date
    Sep 2005

    Pruduct of matrixes

    Hello, all:

    I need to calculate the product of two known matrixes A(1xn) and B(nxn). n is about 30 to 50:


    How calculate the C(1xn) with a program?

  2. #2
    Super Moderater.
    Join Date
    Jan 2005

    Here is a quick although, not complete example...

     A program which performs matrix 
     Multiplication can only take place iff
     the number of columns in matrix A is equal 
     to the number of rows in matrix B.
     Or as I like to remember it:
           C A R B
     Columns in
     A must equal
     Rows in
    #include <iostream>
    using namespace std;
    //Function declarations
    void mmult(int,int,int[][100],int[][100]);
    int main()
        //Hard code matrix A
        int m1[100][100] = {{1,5},
        //Hard code matrix B
        int m2[100][100] = {{8,4,3,1},
        //call function
        //Where '3' is the maximum number of rows in either
        //matrix A or B
        //and '4' is the maximun number of columns in either
        //matrix A or B
       return 0;
    /*=================================================  =====
      Function to multiply matrix
     ==================================================  ===*/                  
    void mmult (int rows, int cols, int m1[][100], int m2[][100]) 
        int m3[100][100];//holds the result of A * B
        for (int i=0; i<rows; i++) 
            for (int j=0; j<cols; j++) 
              int val = 0;
              for (int k=0; k<cols; k++) 
                val = val + m1[i][k] * m2[k][j];
              m3[i][j] = val;
        //print matrix
        for (int i=0; i<rows; i++) 
            for (int j=0; j<cols; j++) 
              cout<<" "<<m3[i][j];
    Last edited by treenef; 01-04-2006 at 04:00 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Books for C matrixes
    By pedofil in forum C Programming
    Replies: 1
    Last Post: 04-17-2008, 04:24 AM
  2. Help with calculations with tables ( matrixes )
    By sdherzo in forum C Programming
    Replies: 11
    Last Post: 06-20-2007, 07:01 AM
  3. multiply 2 matrixes
    By BianConiglio in forum C Programming
    Replies: 2
    Last Post: 04-14-2005, 01:52 AM
  4. OpenGL: Depth Testing, Matrixes, ect.?
    By Zeusbwr in forum Game Programming
    Replies: 8
    Last Post: 12-08-2004, 09:37 AM
  5. matrixes for collision detection
    By DavidP in forum Game Programming
    Replies: 10
    Last Post: 11-09-2002, 10:31 PM