class EtsiiGem::Matriz

Attributes

cols[RW]
data[RW]
rows[RW]

Public Class Methods

new(rows, cols) click to toggle source
# File lib/ETSII_GEM.rb, line 9
def initialize(rows, cols)
        @rows, @cols = rows, cols
end

Public Instance Methods

*(other) click to toggle source
# File lib/ETSII_GEM.rb, line 50
def *(other)
    raise ArgumentError, "Columns and Rows must be equal" unless (@cols == other.rows)
    c = Densa.new(@rows,other.cols)
    @rows.times do |i|
        other.cols.times do |j|
            ac = 0
            @cols.times do |k|
                ac += self[i][k] * other[k][j] if (self[i][k] != nil && other[k][j] != nil)
            end
            c[i][j] = ac
        end
    end
    c
end
+(other) click to toggle source
# File lib/ETSII_GEM.rb, line 12
                       def +(other)
    raise ArgumentError, "El tamaño de las matrices debe ser igual" unless @rows == other.rows && @cols == other.cols
    c = Densa.new(@rows, @cols)
    @rows.times do |i|
        @cols.times do |j|
            if self[i][j] == nil && other[i][j] == nil
                c[i][j] = 0
            elsif self[i][j] == nil && other[i][j] != nil
                c[i][j] = other[i][j]
            elsif self[i][j] != nil && other[i][j] == nil
                c[i][j] = self[i][j]
            else
                c[i][j] = self[i][j] + other[i][j]
            end
        end
    end
    c
end
-(other) click to toggle source
# File lib/ETSII_GEM.rb, line 31
def -(other)
    raise ArgumentError, "El tamaño de las matrices debe ser igual" unless @rows == other.rows && @cols == other.cols
    c = Densa.new(@rows, @cols)
    @rows.times do |i|
        @cols.times do |j|
            if self[i][j] == nil && other[i][j] == nil
                c[i][j] = 0
            elsif self[i][j] == nil && other[i][j] != nil
                c[i][j] = -other[i][j]
            elsif self[i][j] != nil && other[i][j] == nil
                c[i][j] = self[i][j]
            else
                c[i][j] = self[i][j] - other[i][j]
            end
        end
    end
    c
end
max() click to toggle source
# File lib/ETSII_GEM.rb, line 65
def max
    value = 0
    @rows.times do |i|
        @cols.times do |j|
            if self[i][j] != nil
                value = self[i][j] if self[i][j] > value
            end
        end
    end
    value
end
min() click to toggle source
# File lib/ETSII_GEM.rb, line 77
def min
    value = self.max
    @rows.times do |i|
        @cols.times do |j|
            if self[i][j] != nil
                value = self[i][j] if self[i][j] < value
            end
        end
    end
    value
end