Question: Write a method to do matrix multiplication. Write out some of the computations using array indices on paper first to see how you should
Write a method to do matrix multiplication. Write out some of the computations using array indices on paper first to see how you should start programming. On the next slide you will find an example of how to compute multiplication of two 2d arrays. M: 3 x 33 x 2: M2 you can only multiply when these sizes match. The result will always have the leftover sizes. M* M2 will result in a 3x2 array. Recall we can't compute M2 * M in this case because M2: 3 x 23 x 3: M M 012 0 5 7 -9 1 4 0 20 M*M2 0 1 2 0 12 5 28 2 1 2 3 1 17 15 21 M2 012 (5 * 1)+(4 *2)+(1*-1)=5+8+-1=12 (5 * 3)+(4 * 0)+(1 * 2) = 15+0+2=17 3. Then repeat with the rest of the rows. (71)+(0*2)+(2 * -1) = 7+0+-2=5 (73)+(0* 0)+(2 * 2) = 21+0+4=25 0 (-9 * 1)+(20*2)+(3 * -1) = -9+40+-3=28 (-93)+(200)+(3 * 2) = -27+0+5=-21 0 1 2 -1 1 3 0 1. First row of M "dot product" first column of M2 gives first element. 2. First row of M "dot product" second column of M2 gives second element. 2
Step by Step Solution
3.43 Rating (156 Votes )
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
