We will assume that `matrixA` and `matrixB` are valid 2D arrays of * `int`s. Each matrix is rectangular, with each row having the same number * of columns. * * First, we need to make sure the matrices are compatible. Given `numRows X * numColumns` for each matrix `A` and `B`, if `A` is `m x n`, then `B` must * be `n x p`. That is the ``inner`` dimensions (lengths) must match. * * If number of columns in `matrixA` does NOT equal the number of rows in * `matrixB`, then return `null`. That is, not output is created. * * Assuming the dimensions are consistent, then we create a 2D output array * that is `m x p`, that is `numRowsA X numColumnsB`. * * To calculate each element of the output matrix, we multiply the rows of * `A` by the columns of `B` and sum them up. * * For example, let for integer values be given by lower case letters, let * `A` be a 2 x 3 matrix, and `B` a 3 x 3 matrix. The inner dimensions are * consistent, so we can multiply. * * [a, b ,c] A = [d, e, f] [p, q, r] B = |s, t, u| [v, w, x] [a*p + b*s + c*v , a*q + b*t + c*w, a*r + b*u + c*x] C = A*B = [d*p + e*s + f*v , d*q + e*t + f*w, d*r + e*u + f*x] * * * Example with numbers * * C = A*B = [1, 2, 3] [1, 1] [1*1 + 2*10 + 3*100, 1*1 + 2*20 + 3*200] [4, 5, 6]*[10, 20] = [4*1 + 5*10 + 6*100, 4*1 + 5*20 + 6*200] [100, 200] C = [321, 641] [654, 1304] * * * So our 2X3 times 3X2 yields a 2X2 output matrix. * * @param matrixA * a 2D integer array * @param matrixB * a 2D integer array * @return matrixA * matrixB or null if incompatible */ public static int[][] matrixMultiply(int[][] matrixA, int[][] matrixB) {

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

/**
* We will assume that `matrixA` and `matrixB` are valid 2D arrays of
* `int`s. Each matrix is rectangular, with each row having the same number
* of columns.
*
* First, we need to make sure the matrices are compatible. Given `numRows X
* numColumns` for each matrix `A` and `B`, if `A` is `m x n`, then `B` must
* be `n x p`. That is the ``inner`` dimensions (lengths) must match.
*
* If number of columns in `matrixA` does NOT equal the number of rows in
* `matrixB`, then return `null`. That is, not output is created.
*
* Assuming the dimensions are consistent, then we create a 2D output array
* that is `m x p`, that is `numRowsA X numColumnsB`.
*
* To calculate each element of the output matrix, we multiply the rows of
* `A` by the columns of `B` and sum them up.
*
* For example, let for integer values be given by lower case letters, let
* `A` be a 2 x 3 matrix, and `B` a 3 x 3 matrix. The inner dimensions are
* consistent, so we can multiply.
*
* <pre>
[a, b ,c]
A = [d, e, f]

[p, q, r]
B = |s, t, u|
[v, w, x]

[a*p + b*s + c*v , a*q + b*t + c*w, a*r + b*u + c*x]
C = A*B = [d*p + e*s + f*v , d*q + e*t + f*w, d*r + e*u + f*x]
* </pre>
*
* Example with numbers
*
* <pre>
C = A*B = [1, 2, 3] [1, 1] [1*1 + 2*10 + 3*100, 1*1 + 2*20 + 3*200]
[4, 5, 6]*[10, 20] = [4*1 + 5*10 + 6*100, 4*1 + 5*20 + 6*200]
[100, 200]


C = [321, 641]
[654, 1304]
* </pre>
*
* So our 2X3 times 3X2 yields a 2X2 output matrix.
*
* @param matrixA
* a 2D integer array
* @param matrixB
* a 2D integer array
* @return matrixA * matrixB or null if incompatible
*/

public static int[][] matrixMultiply(int[][] matrixA, int[][] matrixB) {

Expert Solution
Step 1

In matrix multiplication, Each element of a row is multiplied of each element of every column. The product of one column is added. This is how matrix multiplication is performed.

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education