(Algebra: add two matrices) Write a function to add two matrices. The header of the function is: def addMatrix (a, b): I
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
(Algebra: add two matrices) Write a function to add two matrices. The header of the function is: def addMatrix (a, b): I
See the image for reference then copy and paste your code. Thank you!
(Algebra: add two matrices) Write a function to add two matrices. The header of the function is: def addMatrix (a, b): In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each element cy is ay + by. For example, for two 3 x 3 matrices a and b, c is a12 a13 b₁ b12 b13 (223)+(245) a31 a32 a33/ b31 by2 b33) Write a test program that prompts the user to enter two 3 x 3 matrices and dis- plays their sum. Here is a sample run: a21 b = (a₁ + b₁₁a₁2 + b₁2 a₂1 + b₂₁ a2 + b₂₂ a31+ b3₁a32 + b32 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 matrices are added as follows: 1.0 2.0 3.0 4.0 5.0 6.0 11.0 8.0 11.0 0.0 2.0 4.0 +1.0 4.5 2.2 1.1 4.3 5.2 = 1.0 4.0 11.0 5.0 11.5 8.2 8.1 12.3 14.2 a13 + b₁3 ₂3 + b₂3 a33 + b33)