VB Eig Decomp Example

← All NMath Code Examples

```Imports System

Imports CenterSpace.NMath.Core

Namespace CenterSpace.NMath.Examples.VisualBasic

A .NET example in Visual Basic demonstrating the features of the eigenvalue decomposition classes.
Module EigDecompExample

Sub Main()

A general m x n system with random entries.
Dim RNG As New RandGenUniform(-1, 1)
RNG.Reset(&H75)
Dim Rows As Integer = 4
Dim Cols As Integer = 4

Dim A As New FloatMatrix(Rows, Cols, RNG)

Construct an eigenvalue decomposition of A.
Dim Decomp As New FloatEigDecomp(A)

Console.WriteLine()

Is it good?
Console.Write("Good? ")
Console.WriteLine(Decomp.IsGood)

Look at the eigenvalues
Console.WriteLine()
Console.Write("Eigenvalues = ")
Console.WriteLine(Decomp.EigenValues)

Look at the left eigenvectors
Console.WriteLine()
Console.WriteLine("Left eigenvectors = ")
Console.WriteLine(Decomp.LeftEigenVectors.ToTabDelimited("G3"))

Look at the right eigenvectors
Console.WriteLine("Right eigenvectors = ")
Console.WriteLine(Decomp.RightEigenVectors.ToTabDelimited("G3"))

The class FloatEigDecompServer allows more control over the computation.
Suppose that you are only interested in the singular values, not the
vectors. You can configure a DoubleComplexSVDecompServer object to
compute just the singular values.

Dim EigServer As New FloatEigDecompServer()
EigServer.ComputeLeftVectors = False
EigServer.ComputeRightVectors = False
EigServer.Balance = BalanceOption.Permute
Decomp = EigServer.Factor(A)

Console.Write("Number of left vectors computed: ")
Console.WriteLine(Decomp.NumberOfLeftEigenVectors)   0

Console.WriteLine()
Console.Write("Number of right vectors computed: ")
Console.WriteLine(Decomp.NumberOfRightEigenVectors)   0

Is it good?
Console.WriteLine()
Console.Write("Good? ")
Console.WriteLine(Decomp.IsGood)

Look at the eigenvalues
Console.WriteLine()
Console.Write("Eigenvalues = ")
Console.WriteLine(Decomp.EigenValues)

Console.WriteLine()
Console.WriteLine("Press Enter Key")