module Properties

Public Instance Methods

col(index) click to toggle source

Returns array with column on index as values. Also aliased as column()

# File lib/matrix_gem/properties_module.rb, line 72
def col(index)
  column = []
  (0..self.m-1).each{ |x| column << self[x, index] }
  column
end
Also aliased as: column
col_length() click to toggle source

Returns the number of columns. Also aliased as n(), col_size(), column_count()

# File lib/matrix_gem/properties_module.rb, line 44
def col_length
  self[0].length
end
Also aliased as: n, col_size
col_size()
Alias for: col_length
column(index)
Alias for: col
column_count()
Alias for: n
diagonal?()
Alias for: is_diagonal
diagonal_values() click to toggle source

Return array with values on main diagonal.

# File lib/matrix_gem/properties_module.rb, line 19
def diagonal_values
  size = ([self.m, self.n].min) -1
  values = []

  (0..size).each do |i|
    values << self[i][i]
  end
  values
end
is_diagonal() click to toggle source

Returns true if there is values not equal to 0 only on main diagonal. Also aliased as diagonal?

# File lib/matrix_gem/properties_module.rb, line 98
def is_diagonal
  (0..self.m-1).each do |i|
    (0..self.m-1).each do |j|
      return false if ((self[i,j] != 0 && i != j))
    end
  end
  true
end
Also aliased as: diagonal?
is_orthogonal()
Alias for: orthogonal?
is_square() click to toggle source

Returns true if this is a matrix with equal rows and columns. Also aliased as square?

# File lib/matrix_gem/properties_module.rb, line 118
def is_square
  return false if self.m != self.n
  true
end
Also aliased as: square?
is_zero()
Alias for: zero?
m()
Also aliased as: row_count
Alias for: row_length
n()
Also aliased as: column_count
Alias for: col_length
orthogonal?() click to toggle source

Returns true if this is square matrix and its transpose is equal to its inverse. Also aliased as is_zero

# File lib/matrix_gem/properties_module.rb, line 126
def orthogonal?
  return true if ((self.is_square) && (self.transposed == self.inversed))
  false
end
Also aliased as: is_orthogonal
row(index) click to toggle source

Retuns array with row on index as values.

# File lib/matrix_gem/properties_module.rb, line 66
def row(index)
  self[index]
end
row_count()
Alias for: m
row_length() click to toggle source

Returns the number of rows. Also aliased as m(), row_size(), row_count()

# File lib/matrix_gem/properties_module.rb, line 50
def row_length
  i = 0
  self.each{ |row| i+=1 }
  i/self[0].length
end
Also aliased as: m, row_size
row_size()
Alias for: row_length
set_col(index, elements) click to toggle source

Set values of matrix column. Elements shoud be an array of values. Raise error if length of elements is not equal to matrix column length.

# File lib/matrix_gem/properties_module.rb, line 90
def set_col(index, elements)
  raise MatrixArgumentError, 'Different length of elements and column length' if elements.length != self.col_length
  (0..self.m-1).each{ |x| self[x, index] = elements[x] }
  self
end
set_diagonal(*nums) click to toggle source

Set values on main diagonal. Raise error if nums are less than matrix main diagonal length Also aliased as set_diagonal_values

# File lib/matrix_gem/properties_module.rb, line 32
def set_diagonal(*nums)
  size = ([self.m, self.n].min) -1
  raise MatrixArgumentError, 'Wrong number of arguments.' if nums.length < size + 1
  (0..size).each do |i|
    self[i,i] = nums[i]
  end
  self
end
Also aliased as: set_diagonal_values
set_diagonal_values(*nums)
Alias for: set_diagonal
set_row(index, elements) click to toggle source

Set values of matrix row. Elements shoud be an array of values Raise error if length of elements is not equal to matrix row length.

# File lib/matrix_gem/properties_module.rb, line 81
def set_row(index, elements)
  raise MatrixArgumentError, 'Different length of elements and row length' if
  elements.length != self.row_length
  self[index] = elements
  self
end
square?()
Alias for: is_square
to_a() click to toggle source

Returns an array of arrays that describe the rows of the matrix.

# File lib/matrix_gem/properties_module.rb, line 6
def to_a
  self
end
to_f() click to toggle source

Make all values floating point.

# File lib/matrix_gem/properties_module.rb, line 11
def to_f
  (0..self.n - 1).each{ |i| (0..self.m - 1).each do
    |j| self[i,j] = self[i,j].to_f
    end }
  self
end
zero?() click to toggle source

Returns true if this is a matrix with only zero elements. Also aliased as is_zero

# File lib/matrix_gem/properties_module.rb, line 110
def zero?
  self.map{ |x| return false if x != 0 }
  true
end
Also aliased as: is_zero