# NMath User's Guide

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

You can create an instance of an LU factorization class by supplying the constructor with a matrix to factor. Thus:

Code Example – C# LU factorization

```var A = new DoubleComplexMatrix( 5, 5, 1, 1 );
```
```var lu = new DoubleComplexLUFact( A );
```

Code Example – VB LU factorization

```Dim A As New DoubleComplexMatrix(5, 5, 1, 1)
```
```Dim LU As New DoubleComplexLUFact(A)
```

You can also use an existing instance to factor other matrices with the provided Factor() method. For instance:

Code Example – C# LU factorization

```var A = new FloatMatrix( n, n, 1, 1.62F );
```
```var lu = new FloatLUFact( A );

```

```B = new FloatVector( n, -1.2F, 1.78F );
```
```lu.Factor( B );
```

Code Example – VB LU factorization

```Dim A As New FloatMatrix(N, N, 1, 1.62F)
```
```Dim LU As New FloatLUFact(A)

```

```Dim B As New FloatVector(N, -1.2F, 1.78F)
```
```LU.Factor(B)
```

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# LU factorization

```if ( lu.IsGood )
```
```{
```
```  // Do something here...
```
```}
```

Code Example – VB LU factorization

```If LU.IsGood Then
```
```  ' Do something here...
```
```End If
```

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

Cols gets the number of columns of the factored matrix.

Rows gets the number of rows of the factored matrix.

IsSingular returns true if the matrix was singular; otherwise, false.

Top

Top