Class: Algebra::MatrixAlgebraTriplet

Inherits:
Object
  • Object
show all
Includes:
ElementaryDivisor, GaussianElimination
Defined in:
lib/algebra/matrix-algebra-triplet.rb

Direct Known Subclasses

MatrixAlgebraQuint

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ElementaryDivisor

#_coeff, #e_diagonalize, #e_diagonalize!, #e_inverse, #el_sweep!, #el_sweep_old!, #elementary_divisor, factorize, #horizontal_sweep!, #sq_find_nondiv, #vertical_sweep!

Methods included from GaussianElimination

#divide_c, #divide_r, #kernel_basis, #left_eliminate_euclidian!, #left_inverse, #left_sweep, #mix_c, #mix_r, #multiply_c, #multiply_r, #step_matrix?, #swap_c, #swap_r

Constructor Details

#initialize(matrix, left = nil, right = nil) ⇒ MatrixAlgebraTriplet

Returns a new instance of MatrixAlgebraTriplet.



26
27
28
29
30
31
32
33
34
# File 'lib/algebra/matrix-algebra-triplet.rb', line 26

def initialize(matrix, left = nil, right = nil)
  @body = matrix
  @type = @body.class
  @ground = @type.ground
  @left_type = Algebra.SquareMatrix(@type.ground, @type.rsize)
  @right_type = Algebra.SquareMatrix(@type.ground, @type.csize)
  @left = left ? left : @left_type.unity
  @right = right ? right : @right_type.unity
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



25
26
27
# File 'lib/algebra/matrix-algebra-triplet.rb', line 25

def body
  @body
end

#groundObject (readonly)

Returns the value of attribute ground.



25
26
27
# File 'lib/algebra/matrix-algebra-triplet.rb', line 25

def ground
  @ground
end

#leftObject (readonly)

Returns the value of attribute left.



25
26
27
# File 'lib/algebra/matrix-algebra-triplet.rb', line 25

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



25
26
27
# File 'lib/algebra/matrix-algebra-triplet.rb', line 25

def right
  @right
end

Instance Method Details

#[](i, j) ⇒ Object



65
66
67
# File 'lib/algebra/matrix-algebra-triplet.rb', line 65

def [](i, j)
  @body[i, j]
end

#csizeObject



73
74
75
# File 'lib/algebra/matrix-algebra-triplet.rb', line 73

def csize
  @body.csize
end

#displayObject



55
56
57
58
59
60
61
62
63
# File 'lib/algebra/matrix-algebra-triplet.rb', line 55

def display
  puts '============= begin'
  @left.display
  puts
  @body.display
  puts
  @right.display
  puts '============= end'
end

#divide_c!(j, c) ⇒ Object

def divide_r(i, c)

  dup.divide_r!(i, c)
end


145
146
147
148
# File 'lib/algebra/matrix-algebra-triplet.rb', line 145

def divide_c!(j, c)
  @body.divide_c!(j, c)
  @right.divide_c!(j, c)
end

#divide_r!(i, c) ⇒ Object

def multiply_c(j, c)

  dup.multiply_c!(j, c)
end


136
137
138
139
# File 'lib/algebra/matrix-algebra-triplet.rb', line 136

def divide_r!(i, c)
  @left.divide_r!(i, c)
  @body.divide_r!(i, c)
end

#dupObject



42
43
44
# File 'lib/algebra/matrix-algebra-triplet.rb', line 42

def dup
  self.class.new(body.dup, left.dup, right.dup)
end

#each_i(&block) ⇒ Object



77
78
79
# File 'lib/algebra/matrix-algebra-triplet.rb', line 77

def each_i(&block)
  @body.each_i(&block)
end

#each_j(&block) ⇒ Object



81
82
83
# File 'lib/algebra/matrix-algebra-triplet.rb', line 81

def each_j(&block)
  @body.each_j(&block)
end

#left_eliminate!Object

def mix_c(i, j, c = nil)

  dup.mix_c!(i, j, c)
end


174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/algebra/matrix-algebra-triplet.rb', line 174

def left_eliminate!
  #    inv = Algebra.SquareMatrix(ground, rsize).unity
  k = ground.unity
  pi = 0
  each_j do |j|
    next unless i = (pi...rsize).find { |i1| !self[i1, j].zero? }
    if i != pi
      swap_r!(pi, i) # ; inv.swap_r!(pi, i)
      k = -k
    end
    c = ground.unity / self[pi, j] # this lets the entries be in ground
    multiply_r!(pi, c) # ; inv.multiply_r!(pi, c)
    k *= c
    each_i do |i0|
      next if i0 == pi
      d = self[i0, j] # / self[pi, j]
      mix_r!(i0, pi, -d) # ; inv.mix_r!(i0, pi, -d)
    end
    pi += 1
  end
  [left, k]
end

#mix_c!(i, j, c = nil) ⇒ Object

def mix_r(i, j, c = nil)

  dup.mix_r!(i, j, c)
end


164
165
166
167
168
# File 'lib/algebra/matrix-algebra-triplet.rb', line 164

def mix_c!(i, j, c = nil)
  @body.mix_c!(i, j, c)
  @right.mix_c!(i, j, c)
  self
end

#mix_r!(i, j, c = nil) ⇒ Object

def divide_c(j, c)

  dup.divide_c!(j, c)
end


154
155
156
157
158
# File 'lib/algebra/matrix-algebra-triplet.rb', line 154

def mix_r!(i, j, c = nil)
  @left.mix_r!(i, j, c)
  @body.mix_r!(i, j, c)
  self
end

#multiply_c!(j, c) ⇒ Object

def multiply_r(i, c)

  dup.multiply_r!(i, c)
end


126
127
128
129
130
# File 'lib/algebra/matrix-algebra-triplet.rb', line 126

def multiply_c!(j, c)
  @body.multiply_c!(j, c)
  @right.multiply_c!(j, c)
  self
end

#multiply_r!(i, c) ⇒ Object

def swap_c(i, j)

  dup.swap_c!(i, j)
end


116
117
118
119
120
# File 'lib/algebra/matrix-algebra-triplet.rb', line 116

def multiply_r!(i, c)
  @left.multiply_r!(i, c)
  @body.multiply_r!(i, c)
  self
end

#replace(other) ⇒ Object



50
51
52
53
# File 'lib/algebra/matrix-algebra-triplet.rb', line 50

def replace(other)
  initialize(other.body, other.left, other.right)
  self
end

#row!(i) ⇒ Object



85
86
87
# File 'lib/algebra/matrix-algebra-triplet.rb', line 85

def row!(i)
  @body.row!(i)
end

#rsizeObject



69
70
71
# File 'lib/algebra/matrix-algebra-triplet.rb', line 69

def rsize
  @body.rsize
end

#sswap_r!(i, j) ⇒ Object

ElementaryOpeartion



90
91
92
93
94
# File 'lib/algebra/matrix-algebra-triplet.rb', line 90

def sswap_r!(i, j)
  @left.sswap_r!(i, j)
  @body.sswap_r!(i, j)
  self
end

#swap_c!(i, j) ⇒ Object

def swap_r(i, j)

  dup.swap_r!(i, j)
end


106
107
108
109
110
# File 'lib/algebra/matrix-algebra-triplet.rb', line 106

def swap_c!(i, j)
  @body.swap_c!(i, j)
  @right.swap_c!(i, j)
  self
end

#swap_r!(i, j) ⇒ Object



96
97
98
99
100
# File 'lib/algebra/matrix-algebra-triplet.rb', line 96

def swap_r!(i, j)
  @left.swap_r!(i, j)
  @body.swap_r!(i, j)
  self
end

#to_aryObject Also known as: to_a



36
37
38
# File 'lib/algebra/matrix-algebra-triplet.rb', line 36

def to_ary
  [body, left, right]
end

#transposeObject



46
47
48
# File 'lib/algebra/matrix-algebra-triplet.rb', line 46

def transpose
  self.class.new(body.transpose, right.transpose, left.transpose)
end