Can any one help me in c++ program for the multiplication of two matrices. in which we input the elements of two matrices and get our desired result.((using structured approach))
Can any one send complete program for it.
Thank you.
Please help me in c++ program for matrices multiplication.?
I will give you an algorithm, but you should write the code yourself.
------------------------
Let M, N, and L be positive integers.
Let A be a matrix of order MxN (M rows and N columns)
Let B be a matrix of order NxL.
(the choice of N as the number of rows in B is a requirement. A*B is a valid matrix multiply if and only if the number of rows in B is the same as the number of columns in A)
Then C = A*B is a MxL matrix defined as follows:
For all i from 1 to M:
...For all j from 1 to L:
......Let S(0), S(1),...S(N) be these partial sums:
......S(0) = 0
......For all k from 1 to N:
.........S(k) = S(k-1) + Aik * Bkj
......Let Cij = S(N)
------------------------
You will have to convert this algorithm into C++ code.
If you use arrays, don't forget that arrays in C++ are zero-based, not one-based like my matrix elements above.
For style points you could set up a Matrix class template with operator*() defined in such a way that Matrix objects that cannot be multiplied together cause a compile error if you attempt to multiply them.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment