module Algebra::Orthogonalization

Public Instance Methods

normalize() click to toggle source
# File lib/algebra/linear-algebra.rb, line 29
def normalize
  k = ground
  orth_basis = []
  vectors.each do |b|
    k, n = Sqrt(k, b.norm2)
    orth_basis.push Vector(k, size)**b / n
  end
  Algebra.SquareMatrix(k, size).collect_column { |j| orth_basis[j] }
end
orthogonalize() click to toggle source
# File lib/algebra/linear-algebra.rb, line 16
def orthogonalize
  orth_basis = []
  vectors.each_with_index do |b, i|
    orth_basis.push b
    next unless i > 0
    orth_basis[0...i].each do |f|
      orth_basis[i] -= b.inner_product(f) / f.norm2 * f
      #       orth_basis[i] = f.norm2*orth_basis[i] - b.inner_product(f)*f #also
    end
  end
  self.class.collect_column { |j| orth_basis[j] }
end