ILNumerics Ultimate VSILMathlinsolve Method (InArrayDouble, InArrayDouble, MatrixProperties, Boolean)ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Solves a system of linear equations, B = Ax, taking hints for the best algorithm.

[ILNumerics Computing Engine]

Namespace: ILNumerics
Assembly: ILNumerics.Computing (in ILNumerics.Computing.dll) Version: (5.3.7131.2749)

public static RetArray<double> linsolve(
	InArray<double> A,
	InArray<double> B,
	ref MatrixProperties props,
	bool throwException = true


Type: ILNumericsInArrayDouble
Input matrix A. Size [n, q].
Type: ILNumericsInArrayDouble
Right hand side B. Size [n, m].
Type: ILNumericsMatrixProperties
[Input, Output] Known / determined matrix properties of A.
throwException (Optional)
Type: SystemBoolean
[Optional] Throws an ArgumentException if A was found to be singular or a specific property in props could not be confirmed. Default: true.

Return Value

Type: RetArrayDouble
Solution x solving the equation multiply(A, x) = B. Size [q, m].

If no specific properties of A are given in props and depending on the actual structure and properties of A the equation system is solved with different approaches:

  • If A is square (q == n) and an upper or lower triangular matrix, the system is solved via backward- or forward substitution and the LAPACK function ?trtrs.

    Array<double> A = randn<double>(4,4); // construct 4 x 4 matrix
                Array<double> B = vector<double>(1.0,2.0,3.0);
                Array<double> x = linsolve(A,B);
  • if A is square, symmetric /hermitian and positive definite A is decomposed into a triangular equation system using cholesky factorization and solved via back-/ forward substitution.

  • otherwise, if A is only square it will be decomposed into upper and lower triangular matrices using LU decomposition and the system is than solved with the triangular result.
  • otherwise, if A' is [n, q] with q != n, the system is solved using qr(InArrayDouble) decomposition. Note that A can be rank deficient.

Specifying known properties of A in props may saves some time in determining these properties. If, for example, A is known to be positive definite, providing PositivDefinite allows the algorithm to perform cholesky factorization with A. However, linsolve(InArrayDouble, InArrayDouble, MatrixProperties, Boolean) determines advantageous properties automatically if required.

After returning the props structure can be inspected fo the matrix properties of A found during the computations. Any bits changed in props by the function reflect the path taken within linsolve(InArrayDouble, InArrayDouble, MatrixProperties, Boolean). However, linsolve(InArrayDouble, InArrayDouble, MatrixProperties, Boolean) does not determine all properties of A automatically. If, let's say: A is found to be singular, the function returns (or throws an exception) without determining further properties of A. In order to query specific properties of A other functionality may be more appropriate.

If throwException is false inspecting the props structure on return is required to verify that a valid solution has been computed. If A was found to be singular and throwException is false then props will have the Singular flag set. If the computation was performed by QR decomposition for a non-square matrix A then the RankDeficient flag may be set.

The internal storage order of A and/or B may be silently changed by this function. The reason is that most functionality is performed in native LAPACK routines which require a certain storage layout (mostly ColumnMajor). Be prepared that both arrays may point to different memory regions for element storage afterwards! This does not, however, affect the handling of the array with common high level functionality (subarrays, element access etc.).

[ILNumerics Computing Engine]

See Also


MathInternal.linsolve(InArrayDouble, InArrayDouble, MatrixProperties, Boolean)
MathInternal.pinv(InArrayDouble, NullableDouble)
MathInternal.svd(InArrayDouble, OutArrayDouble, Boolean)