A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
13
Task/Matrix-multiplication/Icon/matrix-multiplication-1.icon
Normal file
13
Task/Matrix-multiplication/Icon/matrix-multiplication-1.icon
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
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
|
||||
15
Task/Matrix-multiplication/Icon/matrix-multiplication-2.icon
Normal file
15
Task/Matrix-multiplication/Icon/matrix-multiplication-2.icon
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue