• Exercise 10
     
    • Create a method / function, that calculates multiplication operation for
      int[ ][ ] matrixes (2-dimensional arrays), which user gives as parameters.
      If operation is not possible, method should give a proper warning.
    • Furthermore, a proper "validation" code/program(/interface?) is needed
      to test the method/function just created.
    • Multiplication of matrixes goes like this:

      C     =      A     *       B
    p x q        p x n         n x q

  • where…
                    n
    C(j,k) = SUM ( A(j,i) B(i,k) ) ; j = 1,...,p ; k = 1,...,q.
                   i = 1
     
  • So, if for example…
  •        ( 0 5 -3 )
    A = ( 1 2 3 ) and B = ( 4 -1 -1 )
           ( 4 5 6 )              ( -4 -3 3 )
     

  • then…

    A * B = ( 1*0 + 2*4 + 3*(-4) == -4
                    1*5 + 2*(-1) + 3*(-3) == -6
                        1*(-3) + 2*(-1) + 3*3 == 4 ) // "1st row"

                ( 4*0 + 5*4 + 6*(-4) == -4
                    4*5 + 5*(-1) + 6*(-3) == -3
                        4*(-3) + 5*(-1) + 6*3 == 1 ) // "2nd row"

             = ( -4 -6 4 ) // "1st row"
                ( -4 -3 1 ) // "2nd row"
     

  • Back