public static double[][] multiplyMatrix(double[][] a, double[][] b)

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

(Algebra: multiply two matrices) Write a method to multiply two matrices. The header of the method is:

 

public static double[][] multiplyMatrix(double[][] a, double[][] b)

 

To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element cij is ai1 × b1j + ai2 × b2j + g + ain × bnj. For example, for two 3 × 3 matrices a and b, c is

a11    a12     a13

a21    a22      a23

a31    a32      a33

 

where cij = ai1 * b1j + ai2 * b2j + ai3 * b3j .

Write a test program that prompts the user to enter two 3 * 3 matrices and displays their product. 

12. (Algebra: multiply two matrices) Write a method to multiply two matrices. The
header of the method is:
public static double] multiplyMatrix(double[] a, double[]] b)
To multiply matrix a by matrix b, the number of columns in a must be the same
as the number of rows in b, and the two matrices must have elements of the
same or compatible types. Let c be the result of the multiplication. Assume the
column size of matrix a is n. Each element cij is ai1 x b1j + ai2 x b2j + g + ain x
bnj. For example, for two 3 x 3 matrices a and b, c is
b13
C11
C12
C13
bu b12
X| b21
a12
A13
b22
b23
C21
C22
С23
a21
a23
A3,
b31
b32
b33/
C31
C32
C3,
a31
A32
where cij = ai1 * b1j + ai2 * b2j + ai3 * b3j .
%3D
Transcribed Image Text:12. (Algebra: multiply two matrices) Write a method to multiply two matrices. The header of the method is: public static double] multiplyMatrix(double[] a, double[]] b) To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in b, and the two matrices must have elements of the same or compatible types. Let c be the result of the multiplication. Assume the column size of matrix a is n. Each element cij is ai1 x b1j + ai2 x b2j + g + ain x bnj. For example, for two 3 x 3 matrices a and b, c is b13 C11 C12 C13 bu b12 X| b21 a12 A13 b22 b23 C21 C22 С23 a21 a23 A3, b31 b32 b33/ C31 C32 C3, a31 A32 where cij = ai1 * b1j + ai2 * b2j + ai3 * b3j . %3D
SENIOR HIGH SCHOOL
Write a test program that prompts the user to enter two 3 * 3 matrices and
displays their product. Here is a sample run:
Enter matrix1: 1 2 3 4 5 6 7 8 9 -Enter
Enter matrix2: 0 2 4 1 4.5 2.2 1.1 4.3 5.2 -Enter
The multiplication of the matrices is
1 2 3
4 5 6
7 8 9
0 2.0 4.0
5.3 23.9 24
1 4.5 2.2
%3D
11.6 56.3 58.2
1.1 4.3 5.2
17.9 88.7 92.4
Transcribed Image Text:SENIOR HIGH SCHOOL Write a test program that prompts the user to enter two 3 * 3 matrices and displays their product. Here is a sample run: Enter matrix1: 1 2 3 4 5 6 7 8 9 -Enter Enter matrix2: 0 2 4 1 4.5 2.2 1.1 4.3 5.2 -Enter The multiplication of the matrices is 1 2 3 4 5 6 7 8 9 0 2.0 4.0 5.3 23.9 24 1 4.5 2.2 %3D 11.6 56.3 58.2 1.1 4.3 5.2 17.9 88.7 92.4
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr