How to resolve the algorithm Matrix multiplication step by step in the Icon and Unicon programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Matrix multiplication step by step in the Icon and Unicon programming language

Table of Contents

Problem Statement

Multiply two matrices together. They can be of any dimensions, so long as the number of columns of the first matrix is equal to the number of rows of the second matrix.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Matrix multiplication step by step in the Icon and Unicon programming language

Source code in the icon programming language

link matrix

procedure main ()
  m1 := [[1,2,3], [4,5,6]]
  m2 := [[1,2],[3,4],[5,6]]
  m3 := mult_matrix (m1, m2)
  write ("Multiply:")
  write_matrix ("", m1) # first argument is filename, or "" for stdout
  write ("by:")
  write_matrix ("", m2)
  write ("Result: ")
  write_matrix ("", m3)
end


procedure multiply_matrix (m1, m2)
  result := [] # to hold the final matrix
  every row1 := !m1 do { # loop through each row in the first matrix
    row := []
    every colIndex := 1 to *m1 do { # and each column index of the result
      value := 0
      every rowIndex := 1 to *m2 do { 
        value +:= row1[rowIndex] * m2[rowIndex][colIndex]
      }
      put (row, value) 
    }
    put (result, row) # add each row as it is complete
  }
  return result
end


  

You may also check:How to resolve the algorithm Word wheel step by step in the C++ programming language
You may also check:How to resolve the algorithm String case step by step in the GDScript programming language
You may also check:How to resolve the algorithm Floyd-Warshall algorithm step by step in the Raku programming language
You may also check:How to resolve the algorithm Greatest common divisor step by step in the Go programming language
You may also check:How to resolve the algorithm URL decoding step by step in the Oberon-2 programming language