class SparseMatrix::DenseMatrix
Attributes
c[RW]
mat[RW]
r[RW]
Public Class Methods
new(r=0,c=0,matrix=[])
click to toggle source
Calls superclass method
SparseMatrix::AbstractMatrix::new
# File lib/sparse_matrix.rb, line 185 def initialize(r=0,c=0,matrix=[]) super(r,c) @mat = matrix end
Public Instance Methods
*(b)
click to toggle source
# File lib/sparse_matrix.rb, line 243 def *(b) #multiplicacion de matrices, dispersas y densas if b.instance_of? SparseMatrix c = DenseMatrix.new(2,2,[[0.0,0.0],[0.0,0.0]]) 0.upto @mat.length-1 do |i| 0.upto @mat.length-1 do |j| c.mat[i][j]=0 0.upto @mat.length-1 do |k| c.mat[i][j] += @mat[i][k]*b.valor(k,j) end end end c else c = DenseMatrix.new(2,2,[[0.0,0.0],[0.0,0.0]]) 0.upto @mat.length-1 do |i| 0.upto @mat.length-1 do |j| c.mat[i][j]=0 0.upto @mat.length-1 do |k| c.mat[i][j] += @mat[i][k]*b.mat[k][j] end end end c end end
+(b)
click to toggle source
# File lib/sparse_matrix.rb, line 224 def +(b) #suma de matrices, tando densas como dispersas c = DenseMatrix.new(2,2,[[0.0,0.0],[0.0,0.0]]) if b.instance_of? SparseMatrix 0.upto @mat.size-1 do |i| 0.upto @mat.size-1 do |j| c.mat[i][j] = self.mat[i][j]+b.valor(i,j) end end c else 0.upto @mat.size-1 do |i| 0.upto @mat.size-1 do |j| c.mat[i][j] = self.mat[i][j]+b.mat[i][j] end end c end end
print_matrix()
click to toggle source
# File lib/sparse_matrix.rb, line 208 def print_matrix() #metodo que imprime la matrix en pantalla printf "| " for i in (0... @mat.length) for j in (0... @mat.length) if j==0 printf "{ " end printf "#{@mat[i][j]}\t" if j == @mat.length-1 printf " } ," end end end printf "|" end
to_s()
click to toggle source
# File lib/sparse_matrix.rb, line 192 def to_s() #devuelve cadena string s="| " for i in (0... @mat.length) for j in (0... @mat.length) if j==0 s += "{ " end s += "#{@mat[i][j]}\t" if j == @mat.length-1 s += " } , " end end end s += "|" end