Jump to content

How do I find product of the matrices?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
jackson6612

jackson6612

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
Hi

I'm trying to learn to find the product of two matrices using arrays. Please help me. I'm really stuck. And please don't introduce those topics which I won't be able to understand (I'm a beginner). In other words, please keep it simple. Thanks.


// product_of_two_matrices_1x3_and_3x1.cpp

// read two matrices and find product


#include <iostream>

#include <cstdlib>


using namespace std;


int main()

{

        float m1[1][3];

        float m2[3][1];

        float m3[1][3];

        int r, c;


        cout << "Enter matrix #1 below\n\n";


        for ( r=0; r<1; r++)

        {

                for (c=0; c<3 ; c++)

                {

                        cout << "enter entry for row #" << (r+1) << " and column"

                             << " #" << (c+1) << ": ";

                        cin >> m1[r][c];

                }

        }


        cout << "\n\nEnter matrix #2 below\n\n";


        for ( r=0; r<3; r++)

        {

                for (c=0; c<1; c++)

                {

                        cout << "enter entry for row #" << (r+1) << " and column"

                             << " #" << (c+1) << ": ";

                        cin >> m2[r][c];

                }

        }


        cout << "\n\nproduct of matrix #1 and matrix #2 is given below\n\n";


        //[B][COLOR="red"][SIZE="2"]How do I find product of the matrices?[/SIZE][/COLOR][/B]


        return 0;


}


I'm an outright beginner, learning C++. Using Win XP Pro and Code::Blocks. Be nice to me, please.:)

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Your first matrix will be in the following format:

[a,b,c] (1x3)
Second in this

[d,
 e,
 f] (3x1)
There is one row per column in both so it can be multiplied without much trouble:
(a*d + b*e + ...) = product
Try to correlate between rows and columns so that the three corresponding entries of each matrix is multiplied in a loop (and inner loop if you feel it could be done that way easier)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users