Class: MatrizDensa

Inherits:
Matriz show all
Defined in:
lib/matriz.rb

Overview

matriz normal

Instance Attribute Summary

Attributes inherited from Matriz

#columnas, #filas, #matriz

Instance Method Summary collapse

Methods inherited from Matriz

#[], #comprobar, #initialize, #to_s

Methods included from Operatoria

#*, #-, #-@, #==, #Producto_escalar, #[]=

Constructor Details

This class inherits a constructor from Matriz

Instance Method Details

#+(other) ⇒ Object



159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/matriz.rb', line 159

def +(other) 
	suma=MatrizDensa.new(Array.new(@filas,1){Array.new(@columnas,1)})
	filas.times do |i|
        columnas.times do |j|
					if (other.hash_no_ceros.key?("#{i}#{j}"))
						suma.matriz[i][j] = other.hash_no_ceros["#{i}#{j}"] + matriz[i][j]
					else
						suma.matriz[i][j] =  matriz[i][j]
					end
				end
      end
      return suma		
end