Sha256: e7a4778c7ee9163b577fa5d1b2a52c228f14258cd9a9ccdcb1337a1a4fb99975

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require "Fraccion.rb"
class Matriz

attr_accessor :filas, :cols, :matriz

def initialize(m)
@filas = m.size
@cols = m[1].size
@matriz = m
end

def to_s () 
   @matriz.each do |fila|			
   puts fila.join(" ")			
   end
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 
   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
   Matriz.new(aux_m).matriz
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 
   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
   Matriz.new(aux_m).matriz
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   
   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
   Matriz.new(aux_m).matriz
end

def traspuesta ()
   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] = @matriz[(@filas-1)-i][(@cols-1)-j]
      end
   end
   Matriz.new(aux_m).comprobar
end

def comprobar()
   cont_total = 0
   cont_ceros = 0
   for i in 0...@filas do			
      for j in 0...@cols do			
         if @matriz[i][j] == 0
            cont_ceros = cont_ceros + 1
         end
         cont_total = cont_total + 1
      end
   end
   if cont_ceros >= (cont_total * 0.6)
      Matriz_dispersa.new(@matriz)
   else
      Matriz_densa.new(@matriz)
   end
end

def max()
end

def min()
end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
prct09-0.0.1 lib/Matriz.rb