require "Fraccion.rb" require "Matriz.rb" class Matriz_densa < Matriz #Sobrecarga del operador + para operar con matrices densas y dispersas def + (other) aux_m = Array.new @filas.times do |i| aux_m[i] = Array.new @cols.times do |j| aux_m[i][j] = 0; end end if other.is_a?(Matriz_dispersa) @filas.times do |i| @cols.times do |j| 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) @filas.times do |i| @cols.times do |j| aux_m[i][j] = @matriz[i][j] + other.matriz[i][j] end end end Matriz.new(aux_m).comprobar() end #Sobrecarga del operador - para operar con matrices densas y dispersas def - (other) aux_m = Array.new @filas.times do |i| aux_m[i] = Array.new @cols.times do |j| aux_m[i][j] = 0; end end if other.is_a?(Matriz_dispersa) @filas.times do |i| @cols.times do |j| 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) @filas.times do |i| @cols.times do |j| aux_m[i][j] = @matriz[i][j] - other.matriz[i][j] end end end Matriz.new(aux_m).comprobar() end #Sobrecarga del operador * para operar con matrices densas y dispersas def * (other) aux_m = Array.new @filas.times do |i| aux_m[i] = Array.new @cols.times do |j| aux_m[i][j] = 0; end end if other.is_a?(Matriz_dispersa) @filas.times do |i| other.cols.times do |j| other.filas.times do |k| 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) @filas.times do |i| other.cols.times do |j| other.filas.times do |k| aux_m[i][j] += @matriz[i][k] * other.matriz[k][j] end end end end Matriz.new(aux_m).comprobar() end #Calcula el máximo de una matriz densa def max() aux_max = @matriz[0][0] @filas.times do |i| @cols.times do |j| if aux_max < @matriz[i][j] aux_max = @matriz[i][j] end end end aux_max end #Calcula el mínimo de una matriz densa def min() aux_min = @matriz[0][0] @filas.times do |i| @cols.times do |j| if aux_min > @matriz[i][j] aux_min = @matriz[i][j] end end end aux_min end end