Extreme Optimization > Mathematics Library for .NET > QuickStart Samples > SymmetricMatrices QuickStart Sample (VB.NET)

Extreme Optimization Mathematics Library for .NET

SymmetricMatrices QuickStart Sample (VB.NET)

Illustrates the use of the SymmetricMatrix class (Extreme.Mathematics.LinearAlgebra namespace) in Visual Basic .NET.

C# code Back to QuickStart Samples

' The SymmetricMatrix class resides in the Extreme.Mathematics.LinearAlgebra 
' namespace.
Imports Extreme.Mathematics.LinearAlgebra

Namespace Extreme.Mathematics.QuickStart.VB
    ' Illustrates the use of the SymmetricMatrix class in the 
    ' Extreme.Mathematics.LinearAlgebra namespace of the Extreme Optimization
    ' Mathematics Library for .NET.
    Module SymmetricMatrices

        Sub Main()
            ' Symmetric matrices are matrices whose elements
            ' are symmetrical around the main diagonal.
            ' Symmetric matrices are always square, and are
            ' equal to their own transpose.

            '
            ' Constructing symmetric matrices
            '

            ' Constructing symmetric matrices is similar to
            ' constructing general matrices. See the
            ' BasicMatrices QuickStart samples for a more
            ' complete discussion.

            ' Symmetric matrices are always square. You don't
            ' have to specify both the number of rows and the
            ' number of columns.
            '
            ' The following creates a 5x5 symmetric matrix:
            Dim s1 As SymmetricMatrix = New SymmetricMatrix(5)
            ' Symmetric matrices access and modify only the
            ' elements on and either above or below the 
            ' main diagonal. When initializing a
            ' symmetric matrix in a constructor, you must
            ' specify a triangleMode parameter that specifies
            ' whether to use the upper or lower triangle:
            Dim components As Double() = New Double() _
               {11, 12, 13, 14, 15, _
                21, 22, 23, 24, 25, _
                31, 32, 33, 34, 35, _
                41, 42, 43, 44, 45, _
                51, 52, 53, 54, 55}
            Dim s2 As SymmetricMatrix = New SymmetricMatrix( _
                MatrixTriangleMode.Upper, components, 5)
            Console.WriteLine("s2 = {0}", s2)

            ' You can also create a symmetric matrix by
            ' multiplying any matrix by its transpose:
            Dim m As GeneralMatrix = New GeneralMatrix(3, 4, New Double() _
             {1, 2, 3, _
              2, 3, 4, _
              3, 4, 5, _
              4, 5, 6})
            Console.WriteLine("m = {0}", m)
            ' This calculates transpose(m) times m:
            Dim s3 As SymmetricMatrix = _
                SymmetricMatrix.FromOuterProduct(m)
            Console.WriteLine("s3 = {0}", s3)
            ' An optional 'side' parameter lets you specify
            ' whether the left or right operand of the 
            ' multiplication is the transposed matrix.
            ' This calculates m times transpose(m):
            Dim s4 As SymmetricMatrix = _
                SymmetricMatrix.FromOuterProduct(m, _
                    MatrixOperationSide.Right)
            Console.WriteLine("s4 = {0}", s4)

            '
            ' SymmetricMatrix methods
            '

            ' The GetEigenvalues method returns a vector
            ' containing the eigenvalues.
            Dim l As Vector = s4.GetEigenvalues()
            Console.WriteLine("Eigenvalues: {0:F4}", l)

            ' The ApplyMatrixFunction calculates a function 
            ' of the entire matrix. For example, to calculate
            ' the 'sine' of a matrix:
            Dim sinS As SymmetricMatrix = _
                s4.ApplyMatrixFunction(New RealFunction(AddressOf Math.Sin))
            Console.WriteLine("sin(s4): {0:F4}", sinS)

            ' Symmetric matrices don't have any specific
            ' properties.
            '
            ' You can get and set matrix elements:
            s1(1, 3) = 55
            Console.WriteLine("s1(1, 3) = {0}", s1(1, 3))
            ' And the change will automatically be reflected
            ' in the symmetric element:
            Console.WriteLine("s1(3, 1) = {0}", s1(3, 1))

            '
            ' Row and column views
            '

            ' The GetRow and GetColumn methods are
            ' available.
            Dim row As Vector = s2.GetRow(1)
            Console.WriteLine("row 1 of s2 = {0}", row)
            Dim column As Vector = s2.GetColumn(1, 3, 4)
            Console.WriteLine("column of s2 of length 4 at ")
            Console.WriteLine("  row 1, column 3 = {0}", column)

            Console.Write("Press Enter key to exit...")
            Console.ReadLine()

        End Sub

    End Module

End Namespace
Overview
Introduction
Features
Documentation
QuickStart Samples
Sample Applications
Downloads
Get it now!
Download trial version
How to Buy
Search

"The Extreme Optimization Statistics Library for .NET is a major boon for those doing statistical work in .NET. I strongly recommend this product."
- Marc Brooks

"I have made it my mission to institutionalize the value of good API design.  I strongly believe that this is key to making developers more productive and happy on our platform. It is clear that you value good API design in your work, and take to heart developer productivity and synergy with the .NET framework."
- Brad Abrams,
Lead Program Manager, Microsoft.

This is a partial list of companies who are using our libraries:
ABB Robotics
Allstate
Applied Materials
Arcam
Astra Schedule
Babson College
Canadian Council on Learning
Canyon Associates
Caxton Associates
CECity
Constellation Energy
CreditSights
DeepOcean
Duke University
Dynamotive
Elecsoft
Engelhard Corporation
Epcor
Equipoise Software
Galileo International
GAM UK
Gammex
GlaxoSmithKline
Global Matrix
The Hartford
Infinera Corporation
Intel
JDS Uniphase
LaBranche & Co.
Learning & Skills Council
Jacobs Consultancy
Litman Gregory
Lucas Systems
Malvern Instruments
Medrio
Merck & Co.
Mintera.
Monitor Software
MorningStar
NanoString Technologies
Paletta Invent
Parametric Portfolio Associates
Prosanos
RATA Associates
RiskShield
Ramboll
Standard & Poor's
Strategic Analysis Corporation
Univ. of Alicante
Univ. of South Carolina
vielife
Xerox
US Army