Class: Matrix::EigenvalueDecomposition

### Home Classes Methods

### In Files

- lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb

### Parent

Object

### Methods

- ::new
- #d
- #eigenvalue_matrix
- #eigenvalues
- #eigenvector_matrix
- #eigenvector_matrix_inv
- #eigenvectors
- #to_a
- #to_ary
- #v
- #v_inv

### Class/Module Index

Quicksearch

- Prime
- Prime::EratosthenesGenerator
- Prime::EratosthenesSieve
- Prime::Generator23
- Prime::OldCompatibility
- Prime::PseudoPrimeGenerator
- Prime::TrialDivision
- Prime::TrialDivisionGenerator
- Backports
- Backports::MOST_EXTREME_OBJECT_EVER
- Backports::StdLib
- Backports::StdLib::LoadedFeatures
- Enumerator
- Enumerator::GeneratorBP
- Enumerator::Lazy
- Enumerator::Yielder
- Matrix
- Matrix::EigenvalueDecomposition
- Matrix::LUPDecomposition
- Random
- Random::Implementation
- Random::MT19937
- Enumerable
- Enumerable::Enumerator
- File
- File::Constants
- ARGF
- Array
- BasicObject
- Binding
- Complex
- Dir
- ENV
- Fixnum
- Float
- GC
- Hash
- IO
- Integer
- Kernel
- Math
- Method
- Module
- NilClass
- Numeric
- Object
- ObjectSpace
- OpenStruct
- Proc
- Process
- Range
- Regexp
- Set
- StopIteration
- String
- Struct
- Symbol
- UnboundMethod

No matching classes.

# Matrix::EigenvalueDecomposition

Eigenvalues and eigenvectors of a real matrix.

Computes the eigenvalues and eigenvectors of a matrix A.

If A is diagonalizable, this provides matrices V and D such that A = V*D*V.inv, where D is the diagonal matrix with entries equal to the eigenvalues and V is formed by the eigenvectors.

If A is symmetric, then V is orthogonal and thus A = V*D*V.t

### Public Class Methods

new(a) click to toggle source

Constructs the eigenvalue decomposition for a square matrix `A`

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 18
    def initialize(a)
      # @d, @e: Arrays for internal storage of eigenvalues.
      # @v: Array for internal storage of eigenvectors.
      # @h: Array for internal storage of nonsymmetric Hessenberg form.
      raise TypeError, "Expected Matrix but got #{a.class}" unless a.is_a?(Matrix)
      @size = a.row_size
      @d = Array.new(@size, 0)
      @e = Array.new(@size, 0)

      if (@symmetric = a.symmetric?)
        @v = a.to_a
        tridiagonalize
        diagonalize
      else
        @v = Array.new(@size) { Array.new(@size, 0) }
        @h = a.to_a
        @ort = Array.new(@size, 0)
        reduce_to_hessenberg
        hessenberg_to_real_schur
      end
    end

### Public Instance Methods

d() click to toggle source
Alias for: eigenvalue_matrix
eigenvalue_matrix() click to toggle source

Returns the block diagonal eigenvalue matrix `D`

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 72
    def eigenvalue_matrix
      Matrix.diagonal(*eigenvalues)
    end

Also aliased as: d
eigenvalues() click to toggle source

Returns the eigenvalues in an array

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 58
    def eigenvalues
      values = @d.dup
      @e.each_with_index{|imag, i| values[i] = Complex(values[i], imag) unless imag == 0}
      values
    end

eigenvector_matrix() click to toggle source

Returns the eigenvector matrix `V`

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 42
    def eigenvector_matrix
      Matrix.send :new, build_eigenvectors.transpose
    end

Also aliased as: v
eigenvector_matrix_inv() click to toggle source

Returns the inverse of the eigenvector matrix `V`

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 49
    def eigenvector_matrix_inv
      r = Matrix.send :new, build_eigenvectors
      r = r.transpose.inverse unless @symmetric
      r
    end

Also aliased as: v_inv
eigenvectors() click to toggle source

Returns an array of the eigenvectors

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 66
    def eigenvectors
      build_eigenvectors.map{|ev| Vector.send :new, ev}
    end

to_a() click to toggle source
Alias for: to_ary
to_ary() click to toggle source

Returns [eigenvector_matrix, eigenvalue_matrix, eigenvector_matrix_inv]

    # File lib/backports/1.9.2/stdlib/matrix/eigenvalue_decomposition.rb, line 79
    def to_ary
      [v, d, v_inv]
    end

Also aliased as: to_a
v() click to toggle source
Alias for: eigenvector_matrix
v_inv() click to toggle source
Alias for: eigenvector_matrix_inv

[Validate]

Generated with the Darkfish Rdoc Generator 2.