
- Forum
- Programming Talk
- C and C++
- How to write a program to implement matrix
How to write a program to implement matrix
This is a discussion on How to write a program to implement matrix within the C and C++ forums, part of the Programming Talk category; I need a help to write a program to implement the multiplication of 2 (3x3) matrix....
-
06-02-2011, 08:19 PM #1
- Join Date
- May 2011
- Location
- Dianou, Bouafle, Cote D'Ivoire, Côte d'Ivoire
- Answers
- 1
How to write a program to implement matrix
I need a help to write a program to implement the multiplication of 2 (3x3) matrix.
-
Pince, You need to make use of loops and arrays. Set the value of two matrices in an array then you can multiply as follows
product_result = product_result+matrix_1[i][j]*matrix_2[j][k];
result_matrix[i][k]=product_result;
Here while writing the program one must remember that in matrix multiplication, the number of columns of first matrix must be equal to the number of rows of second matrix.
-
I think you should make use of a two dimensional array to handle this type of problem. You need to have 3 2D arrays. Two for the initial arrays to calculate for and one for the result.
I am not that sure how the exact formula would look like but you have to save them on the third matrix so you could use it.
There is also an implementation that would require a one dimensional array though it would be harder as you have to take note of the constants to know how you will gather the results.
-
I think the most straight forward approach would be to make use of a 2d array with the bounds set to the corresponding x and y of your matrix.
If you are going to access each one of them, I suggest that you use a loop within a loop to make everything automated. Though, if you concern would be the big oh of the whole code, then this would not be an option for you because that alone would ensure a big oh of n squared.
-
Sponsored Ads
«
DataStructures using C language Tutorial
|
object based programming and object oriented programming
»

Reply With Quote





