Given two matrices A and B. The task is to multiply matrix A and matrix B recursively. If matrix A and matrix B are not multiplicative compatible, then generate output “Not Possible”.
Input: A = 12 56 45 78 B = 2 6 5 8 Output: 304 520 480 894 Input: A = 1 2 3 4 5 6 7 8 9 B = 1 2 3 4 5 6 7 8 9 Output: 30 36 42 66 81 96 102 126 150
It is recommended to first refer Iterative Matrix Multiplication.
First check if multiplication between matrices is possible or not. For this, check if number of columns of first matrix is equal to number of rows of second matrix or not. If both are equal than proceed further otherwise generate output “Not Possible”.
In Recursive Matrix Multiplication, we implement three loops of Iteration through recursive calls. The inner most Recursive call of multiplyMatrix() is to iterate k (col1 or row2). The second recursive call of multiplyMatrix() is to change the columns and the outermost recursive call is to change rows.
Below is Recursive Matrix Multiplication code.
30 36 42 66 81 96 102 126 150
This article is contributed by Anuj Chauhan. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Multiplication of Matrix using threads
- Matrix Chain Multiplication | DP-8
- Program for scalar multiplication of a matrix
- Matrix Chain Multiplication (A O(N^2) Solution)
- Divide and Conquer | Set 5 (Strassen's Matrix Multiplication)
- Strassen’s Matrix Multiplication Algorithm | Implementation
- Printing brackets in Matrix Chain Multiplication Problem
- Printing Matrix Chain Multiplication (A Space Optimized Solution)
- Minimum number of steps to convert a given matrix into Diagonally Dominant Matrix
- Minimum steps required to convert the matrix into lower hessenberg matrix
- Minimum number of steps to convert a given matrix into Upper Hessenberg matrix
- Check if matrix can be converted to another matrix by transposing square sub-matrices
- Multiplication of two Matrices in Single line using Numpy in Python
- Program to check diagonal matrix and scalar matrix
- Circular Matrix (Construct a matrix with numbers 1 to m*n in spiral way)