Extreme Optimization > QuickStart Samples > Linear Equations QuickStart Sample (VB.NET)

Extreme Optimization QuickStart Samples

Linear Equations QuickStart Sample (VB.NET)

Illustrates how to solve systems of simultaneous linear equations using the Matrix and LUDecomposition classes (Extreme.Mathematics.LinearAlgebra namespace) in Visual Basic .NET.

C# code Back to QuickStart Samples

' The GeneralMatrix and LUDecomposition classes reside in the 
' Extreme.Mathematics.LinearAlgebra namespace.
Imports Extreme.Mathematics.LinearAlgebra

Namespace Extreme.Mathematics.QuickStart.VB

    ' Illustrates solving systems of simultaneous linear
    ' equations using the GeneralMatrix and LUDecomposition classes 
    ' in the Extreme.Mathematics.LinearAlgebra namespace of the Extreme 
    ' Optimization Mathematics Library for .NET.
    Module LinearEquations

        Sub Main()
            ' A system of simultaneous linear equations is
            ' defined by a square matrix A and a right-hand
            ' side B, which can be a vector or a matrix.
            '
            ' You can use any matrix type for the matrix A.
            ' The optimal algorithm is automatically selected.

            ' Let's start with a general matrix:
            Dim m As GeneralMatrix = New GeneralMatrix(4, 4, New Double() _
                {1, 1, 1, 1, _
                 1, 2, 3, 4, _
                 1, 4, 9, 16, _
                 1, 2, 1, 2})
            Dim b1 As Vector = New GeneralVector(1, 3, 6, 3)
            Dim b2 As GeneralMatrix = New GeneralMatrix(4, 2, New Double() _
                {1, 3, 6, 3, _
                 2, 3, 5, 8})
            Console.WriteLine("m = {0}", m)

            '
            ' The Solve method
            '

            ' The following solves m x = b1. The second 
            ' parameter specifies whether to overwrite the
            ' right-hand side with the result.
            Dim x1 As Vector = m.Solve(b1, False)
            Console.WriteLine("x1 = {0}", x1)
            ' If the overwrite parameter is omitted, the
            ' right-hand-side is overwritten with the solution:
            m.Solve(b1)
            Console.WriteLine("b1 = {0}", b1)
            ' You can solve for multiple right hand side 
            ' vectors by passing them in a GeneralMatrix:
            Dim x2 As GeneralMatrix = m.Solve(b2, False)
            Console.WriteLine("x2 = {0}", x2)

            '
            ' Related Methods
            '

            ' You can verify whether a matrix is singular
            ' using the IsSingular method:
            Console.WriteLine("IsSingular(m) = {0}", _
                m.IsSingular())
            ' The inverse matrix is returned by the GetInverse
            ' method:
            Console.WriteLine("GetInverse(m) = {0}", m.GetInverse())
            ' The determinant is also available:
            Console.WriteLine("Det(m) = {0}", m.GetDeterminant())
            ' The condition number is an estimate for the
            ' loss of precision in solving the equations
            Console.WriteLine("Cond(m) = {0}", m.EstimateConditionNumber())
            Console.WriteLine()

            '
            ' The LUDecomposition class
            '

            ' If multiple operations need to be performed
            ' on the same matrix, it is more efficient to use
            ' the LUDecomposition class. This class does the
            ' bulk of the calculations only once.
            Console.WriteLine("Using LU Decomposition:")
            ' The constructor takes an optional second argument
            ' indicating whether to overwrite the original
            ' matrix with its decomposition:
            Dim lu As LUDecomposition = New LUDecomposition(m, False)
            ' All methods mentioned earlier are still available:
            x2 = lu.Solve(b2, False)
            Console.WriteLine("x2 = {0}", x2)
            Console.WriteLine("IsSingular(m) = {0}", _
                lu.IsSingular())
            Console.WriteLine("GetInverse(m) = {0}", lu.GetInverse())
            Console.WriteLine("Det(m) = {0}", lu.GetDeterminant())
            Console.WriteLine("Cond(m) = {0}", lu.EstimateConditionNumber())
            ' In addition, you have access to the
            ' components, L and U of the decomposition.
            ' L is lower unit-triangular:
            Console.WriteLine("  L = {0}", lu.LowerTriangularFactor)
            ' U is upper triangular:
            Console.WriteLine("  U = {0}", lu.UpperTriangularFactor)

            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
Information
Resources
Contact Us
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