Skip Navigation Links
Numerical Libraries
Linear Algebra
Differential Equations
Optimization
Samples
Linear Algebra
Optimization
Differential Equations

System of Linear Equations.

The LinearEquations class computes the solution to a real system of linear equations (general, band and tridiagonal matrices): A * X = B.

 In this example the LinearEquations class is used to solve:

            2*x1 + 5*x2 + 3*x3 = 5;
            1*x1 + 5*x2 + 7*x3 = 3;
            8*x1 + 2*x2 + 3*x3 = 8;

C# Code

using DotNumerics.LinearAlgebra;
using DotNumerics;
 
 
public void LinearAlgebraSolve()
{
    //using DotNumerics.LinearAlgebra;
    //using DotNumerics;
 
    Matrix A = new Matrix(3, 3);
    A[0, 0] = 2; A[0, 1] = 5; A[0, 2] = 3;
    A[1, 0] = 1; A[1, 1] = 5; A[1, 2] = 7;
    A[2, 0] = 8; A[2, 1] = 2; A[2, 2] = 3;
 
    Matrix B = new Matrix(3, 1);
    B[0, 0] = 5;
    B[1, 0] = 3;
    B[2, 0] = 8;
 
    LinearEquations leq = new LinearEquations();
    Matrix X = leq.Solve(A, B);
 
    Matrix AXmB = A * X - B;
 
}

Solution


A=
2.000, 5.000, 3.000, 
1.000, 5.000, 7.000, 
8.000, 2.000, 3.000, 

B=
5.000, 
3.000, 
8.000, 

X=
0.902, 
0.804, 
-0.275, 

AXmB(A*X-B) =
0.000, 
0.000, 
0.000, 

Skip Navigation LinksHome > Numerical Libraries > Samples > Linear Equations