require "Fraccion.rb" require "Matriz.rb" class Matriz_densa < Matriz def + (other) aux_m = Array.new for i in 0...@filas do aux_m[i] = Array.new for j in 0...@cols do aux_m[i][j] = 0; end end if other.is_a?(Matriz_dispersa) for i in 0...@filas do for j in 0...@cols do if other.matriz[i.to_s+"_"+j.to_s] != nil aux_m[i][j] = @matriz[i][j] + other.matriz[i.to_s+"_"+j.to_s] else aux_m[i][j] = @matriz[i][j] end end end elsif other.is_a?(Matriz_densa) for i in 0...@filas do for j in 0...@cols do aux_m[i][j] = @matriz[i][j] + other.matriz[i][j] end end end Matriz.new(aux_m).comprobar() end def - (other) aux_m = Array.new for i in 0...@filas do aux_m[i] = Array.new for j in 0...@cols do aux_m[i][j] = 0; end end if other.is_a?(Matriz_dispersa) for i in 0...@filas do for j in 0...@cols do if other.matriz[i.to_s+"_"+j.to_s] != nil aux_m[i][j] = @matriz[i][j] - other.matriz[i.to_s+"_"+j.to_s] else aux_m[i][j] = @matriz[i][j] end end end elsif other.is_a?(Matriz_densa) for i in 0...@filas do for j in 0...@cols do aux_m[i][j] = @matriz[i][j] - other.matriz[i][j] end end end Matriz.new(aux_m).comprobar() end def * (other) aux_m = Array.new for i in 0...@filas do aux_m[i] = Array.new for j in 0...@cols do aux_m[i][j] = 0; end end if other.is_a?(Matriz_dispersa) for i in 0...@filas do for j in 0...other.cols do for k in 0...other.filas do if other.matriz[k.to_s+"_"+j.to_s] != nil aux_m[i][j] += @matriz[i][j] * other.matriz[k.to_s+"_"+j.to_s] end end end end elsif other.is_a?(Matriz_densa) for i in 0...@filas do for j in 0...other.cols do for k in 0...other.filas do aux_m[i][j] += @matriz[i][k] * other.matriz[k][j] end end end end Matriz.new(aux_m).comprobar() end def max() aux_max = @matriz[0][0] for i in 0...@filas do for j in 0...@cols do if aux_max < @matriz[i][j] aux_max = @matriz[i][j] end end end aux_max end def min() aux_min = @matriz[0][0] for i in 0...@filas do for j in 0...@cols do if aux_min > @matriz[i][j] aux_min = @matriz[i][j] end end end aux_min end end