class Matrizdispersa
Attributes
matrix[R]
Public Class Methods
new(h = {})
click to toggle source
# File lib/matrixfamily/matrizdispersa.rb, line 42 def initialize(h = {}) @matrix = Hash.new(0) for k in h.keys do @matrix[k] = if h[k].is_a? Vectordisperso h[k] else @matrix[k] = Vectordisperso.new(h[k]) end end end
Public Instance Methods
*(other)
click to toggle source
MULTIPLICACION
# File lib/matrixfamily/matrizdispersa.rb, line 86 def *(other) ms = Hash.new(0) h = Hash.new(0) @mul = 0 for k in @matrix.keys do for j in 0..other.hash.keys.count do for i in @matrix[k].keys do if other.hash[i][j] != 0 then @mul += @matrix[k][i] * other.hash[i][j] end end h[j] = @mul unless @mul == 0 @mul = 0 end ms[k] = h.clone unless h.empty? h.clear end ms2 = Matrizdispersa.new(ms) end
+(other)
click to toggle source
SUMA
# File lib/matrixfamily/matrizdispersa.rb, line 74 def +(other) ms = @matrix.clone ms.merge!(other.hash){ |key, oldval, newval| newval + oldval} end
-(other)
click to toggle source
RESTA
# File lib/matrixfamily/matrizdispersa.rb, line 80 def -(other) ms = @matrix.clone ms.merge!(other.hash){ |key, oldval, newval| newval - oldval} end
[](i)
click to toggle source
# File lib/matrixfamily/matrizdispersa.rb, line 53 def [](i) @matrix[i] end
col(j)
click to toggle source
# File lib/matrixfamily/matrizdispersa.rb, line 65 def col(j) c = {} for r in @matrix.keys do c[r] = @matrix[r].vector[j] if @matrix[r].vector.keys.include? j end Vectordisperso.new c end
hash()
click to toggle source
# File lib/matrixfamily/matrizdispersa.rb, line 57 def hash @matrix end
keys()
click to toggle source
# File lib/matrixfamily/matrizdispersa.rb, line 61 def keys @matrix.keys end