class Matriz
Attributes
col[R]
row[R]
Public Class Methods
new(row,col)
click to toggle source
# File lib/matrc/matriz.rb, line 7 def initialize(row,col) @row,@col = row,col end
Public Instance Methods
*(other)
click to toggle source
# File lib/matrc/matriz.rb, line 22 def *(other) if(self.col == other.row) matres = self.class.new(self.row,self.col) for i in 0...self.row for j in 0...other.col for k in 0...self.col matres[i,j] += self[i,k] * other[k,j] end end end matres end end
+(other)
click to toggle source
# File lib/matrc/matriz.rb, line 36 def +(other) if(self.col == other.col && other.row == self.row) matres = self.class.new(self.row,self.col) for i in 0...self.row for j in 0...self.col matres[i,j] = self[i,j] + other[i,j] end end matres end end
-(other)
click to toggle source
# File lib/matrc/matriz.rb, line 48 def -(other) if(self.col == other.col && other.row == self.row) matres = self.class.new(self.row,self.col) for i in 0...self.row for j in 0...self.col matres[i,j] = self[i,j] - other[i,j] end end matres end end
==(other)
click to toggle source
# File lib/matrc/matriz.rb, line 60 def ==(other) if (self.row != other.row || self.col != other.col) return false end for i in 0...self.row for j in 0...self.col if(self[i, j] != other[i,j]) return false end end end return true end
each() { |self| ... }
click to toggle source
# File lib/matrc/matriz.rb, line 74 def each for i in 0...self.row for j in 0...self.col yield self[i, j] end end end
max()
click to toggle source
# File lib/matrc/matriz.rb, line 82 def max max = -9999 for i in 0...@row for j in 0...@col if(self[i,j] > max) max = self[i,j] end end end max end
min()
click to toggle source
# File lib/matrc/matriz.rb, line 94 def min min = 9999 for i in 0...@row for j in 0...@col if(self[i,j] < min) min = self[i,j] end end end min end
to_s()
click to toggle source
# File lib/matrc/matriz.rb, line 11 def to_s aux = "" for i in 0...self.row for j in 0...self.col aux << "#{self[i,j]}" end aux << "\n" end aux end