Clase que hereda de la clase matriz. Almacena matrices densas.
crea una matriz con n filas, m columnas y almacena los valores que se le pasan por parĂ¡metros
# File lib/matrices_p9.rb, line 233 def initialize(f,c,e) super(f,c) @mat = Array.new(@fil.to_i){Array.new(@col.to_i)} #k2 if (e != nil) #Rellenamos la matriz con lo valores recibidos for i in (0...@fil.to_i) for j in (0...@col.to_i) @mat[i][j]=e[i*@col.to_i+j]; end end end end
Operador de comparacion (Modulo comparable). se comparan por la suma de sus componentes.
# File lib/matrices_p9.rb, line 288 def <=> (other) return nil unless other.is_a?MatrizDensa c1=0 c2=0 for i in (0...@fil.to_i) for j in (0...@col.to_i) if(self.mat[i][j] > other.mat[i][j]) c1+=1 elsif(self.mat[i][j] < other.mat[i][j]) c2+=1 end end end (c1)<=>(c2) end
funcion que calcula el mayor valor que se encuentra en la matriz
# File lib/matrices_p9.rb, line 258 def max m = self.mat[0][0] for i in (0...@fil.to_i) #for j in (0...@col.to_i) @col.to_i.times do |j| if (self.mat[i][j] > m) m = self.mat[i][j] end end end return m end
funcion que calcula el menor valor que se encuentra en la matriz
# File lib/matrices_p9.rb, line 273 def min m = self.mat[0][0] for i in (0...@fil.to_i) #for j in (0...@col.to_i) @col.to_i.times do |j| if (self.mat[i][j] < m) m = self.mat[i][j] end end end return m end
Generated with the Darkfish Rdoc Generator 2.