Module: Algebra::Orthogonalization
- Included in:
- MatrixAlgebra
- Defined in:
- lib/algebra/linear-algebra.rb
Instance Method Summary collapse
Instance Method Details
#normalize ⇒ Object
29 30 31 32 33 34 35 36 37 |
# 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 ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# 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 |