class Matriz
Attributes
columnas[RW]
filas[RW]
matriz[RW]
Public Class Methods
new(m)
click to toggle source
# File lib/matriz.rb, line 15 def initialize(m) @filas = m.size @columnas = m[0].size @matriz = m; end
Public Instance Methods
*(num)
click to toggle source
# File lib/matriz.rb, line 79 def * num #Método que multiplica un número por una matriz mat = Matriz.new(self.matriz) for i in (0...filas) for j in (0...columnas) mat.matriz[i][j] = (matriz[i][j] * num) end end mat end
+(matAux)
click to toggle source
# File lib/matriz.rb, line 89 def + matAux #Método para hacer la suma de de matrices mat = Matriz.new(matAux.matriz) for i in (0...filas) for j in (0...columnas) mat.matriz[i][j] = (matriz[i][j] + matAux.matriz[i][j]) end end mat end
-(matAux)
click to toggle source
# File lib/matriz.rb, line 99 def - matAux #Método para hacer la resta de matrices mat = Matriz.new(matAux.matriz) for i in (0...filas) for j in (0...columnas) mat.matriz[i][j] = (matriz[i][j] - matAux.matriz[i][j]) end end mat end
-@()
click to toggle source
# File lib/matriz.rb, line 67 def -@ # Sobrecarga del operador - para calcular el opuesto de una matriz mat = Matriz.new(self.matriz) for i in (0...filas) for j in (0...columnas) if matriz[i][j] != 0 mat.matriz[i][j] = (matriz[i][j] * -1) end end end mat end
[](fila, columna)
click to toggle source
# File lib/matriz.rb, line 21 def [](fila, columna) @matriz[fila][columna] end
[]=(fila, columna, valor)
click to toggle source
# File lib/matriz.rb, line 25 def []=(fila, columna, valor) @matriz[fila][columna] = valor end
max()
click to toggle source
# File lib/matriz.rb, line 122 def max maximo = 0.to_f for i in 0...matriz.size for j in 0...matriz[i].size if matriz[i][j].to_f > maximo maximo = matriz[i][j].to_f end end end maximo end
min()
click to toggle source
# File lib/matriz.rb, line 134 def min minimo = 1000 for i in 0...matriz.size for j in 0...matriz[i].size if matriz[i][j].to_f < minimo minimo = matriz[i][j].to_f end end end minimo end
to_f()
click to toggle source
# File lib/matriz.rb, line 48 def to_f # Método encargado de mostrar por la consola la matriz en formato flotante s = "" s = "{" for i in (0...filas) s += "{" for j in (0...columnas) if j == 0 s += "#{matriz[i][j].to_f}" else s += "," s += "#{matriz[i][j].to_f}" end end s += "}" end s += "}" s end
to_s()
click to toggle source
# File lib/matriz.rb, line 29 def to_s #Método encargado de mostrar por consola la matriz de forma matriz[i][j] s = "" s += "{" for i in (0...filas) s += "{" for j in (0...columnas) if j == 0 s += "#{matriz[i][j]}" else s += "," s += "#{matriz[i][j]}" end end s += "}" end s += "}" s end