# Linear algebra module for matrix operation etc. # # First written by k-fleak # Time-stamp: <05/10/08> module LinearAlgebra def defZeroMatrix(row, col) (0...row).collect {Array.new(col).fill(0)} end def multiply(mat1, mat2) mat = defZeroMatrix(mat1.size, mat2[0].size) mat1.size.times do |i| mat2[0].size.times do |j| mat1[0].size.times do |k| mat[i][j] += mat1[i][k]*mat2[k][j] end end end mat end end