Class: Orthogonal_Matrix

Inherits:
Matrix
  • Object
show all
Defined in:
lib/matrix_gem/orthogonal_matrix.rb

Instance Method Summary collapse

Methods inherited from Matrix

#*, #**, #+, #-, #/, #==, #[], #det, diagonal, #each, identity, #inverse, #inversed, #minor, #to_str, #transpose, #transposed, zero

Methods included from Properties

#col, #col_length, #diagonal_values, #is_diagonal, #is_square, #orthogonal?, #row, #row_length, #set_col, #set_diagonal, #set_row, #to_a, #to_f, #zero?

Constructor Details

#initialize(rows, cols, *nums) ⇒ Orthogonal_Matrix

Initialize orthogonal matrix (square matrix and its transpose is equal to its inverse).



4
5
6
7
8
9
10
11
12
13
# File 'lib/matrix_gem/orthogonal_matrix.rb', line 4

def initialize(rows, cols, *nums)
  if !(Matrix.new rows, cols, *(nums)).orthogonal?
    raise MatrixArgumentError,
    "Can't initialize orthogonal matrix with this values."
  elsif nums.length == 0
      @matrix = identity rows
  else
    @matrix = matrix_with_values nums, cols
  end
end

Instance Method Details

#[]=(i, j, value) ⇒ Object

Set element. Raise error if the matrix with new value is not orthogonal.



17
18
19
20
21
22
23
24
25
# File 'lib/matrix_gem/orthogonal_matrix.rb', line 17

def []=(i, j, value)
  b = copy(self)
  b[i,j] = value
  if b.orthogonal?
    @matrix[i][j] = value
  else
    raise MatrixIndexOutOfRange, 'The matrix must be orthogonal.'
  end
end