F# Eig Decomp Example

← All NMath Code Examples

 

#light

namespace CenterSpace.NMath.Examples.FSharp

open System

open CenterSpace.NMath.Core

  /// <summary>
  /// A .NET example in C# demonstrating the features of the eigenvalue decomposition classes.
  /// </summary>
module EigDecompExample =

  // A general m x n system with random entries.
  let rng = new RandGenUniform(-1.0, 1.0)
  rng.Reset(0x75) |> ignore
  let rows = 4
  let cols = 4
  let A = new FloatMatrix(rows, cols, rng)

  // Construct an eigenvalue decomposition of A.
  let mutable decomp = new FloatEigDecomp(A)

  // Is it good
  printfn ""  
  printfn "Good? %A" decomp.IsGood

  // Look at the eigenvalues
  printfn ""
  printfn "Eigenvalues = %s" (decomp.EigenValues.ToString())

  // Look at the left eigenvectors
  printfn ""
  printfn "Left eigenvectors = %s" (decomp.LeftEigenVectors.ToString())

  // Look at the right eigenvectors
  printfn ""
  printfn "Right eigenvectors = %s" (decomp.RightEigenVectors.ToString())

  // 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.

  let eigServer = new FloatEigDecompServer()
  eigServer.ComputeLeftVectors <- false
  eigServer.ComputeRightVectors <- false
  eigServer.Balance <- BalanceOption.Permute
  decomp <- eigServer.Factor(A)

  printfn ""
  printfn "Number of left vectors computed: %A" decomp.NumberOfLeftEigenVectors // 0

  printfn ""
  printfn "Number of right vectors computed: %A" decomp.NumberOfRightEigenVectors // 0

  // Is it good?
  printfn ""
  printfn "Good? %A" decomp.IsGood

  // Look at the eigenvalues
  printfn ""
  printfn "Eigenvalues = %s" (decomp.EigenValues.ToString())

  printfn ""
  printfn "Press Enter Key"
  Console.Read() |> ignore



← All NMath Code Examples
Top