NMath User's Guide

TOC | Previous | Next | Index

20.2 Creating Factorizations (.NET, C#, CSharp, VB, Visual Basic, F#)

You can create an instance of a factorization class by supplying the constructor with a matrix to factor. This code creates a 12 x 12 FloatBandMatrix, with upper bandwidth of 1 and lower bandwidth of 2 and values generated randomly from the interval -1 to 1, then factors the matrix using the FloatBandFact class constructor:

Code Example – C# matrix factorization

int rows = 12, cols = 12, ub = 1, lb = 2;
FloatVector data =
   new FloatVector( cols*(ub+lb+1), new RandGenUniform(-1, 1) );
FloatBandMatrix A =
   new FloatBandMatrix( data, rows, cols, lb, ub );

var F = new FloatBandFact( A );

Code Example – VB matrix factorization

Dim Rows As Integer = 12
Dim Cols As Integer = 12
Dim UB As Integer = 1
Dim LB As Integer = 2
Dim Data As New FloatVector(Cols * (UB + LB + 1),
  New RandGenUniform(-1.0, 1.0))
Dim A As New FloatBandMatrix(Data, Rows, Cols, LB, UB)

Dim F As New FloatBandFact(A)

You can also use an existing instance to factor other matrices with the provided Factor() method. Thus, if B is another FloatBandMatrix:

Code Example – C# matrix factorization

F.Factor( B );

Code Example – VB matrix factorization


The read-only IsGood property gets a boolean value that is true if the matrix factorization succeeded and the factorization may be used to solve equations, compute determinants, inverses, and so on. Otherwise, it returns false. For example:

Code Example – C# matrix factorization

if ( F.IsGood ) 
   // Do something here...

Code Example – VB matrix factorization

If F.IsGood Then
  ' Do something here...
End If

Other read-only properties provide information about the matrix used to construct an factorization:

Cols gets the number of columns of the factored matrix.

Rows gets the number of rows of the factored matrix.

On indefinite factorization classes, IsSingular returns true if the matrix was singular; otherwise, false.

On positive definite factorization classes, IsPositiveDefinite returns true if the matrix was positive definite; otherwise, false.