WOLFRAM SYSTEM MODELER
LU_solve2Solve real system of linear equations P*L*U*X=B with a B matrix and an LU decomposition (from LU(..)) |
SystemModel["Modelica.Math.Matrices.LU_solve2"]
This information is part of the Modelica Standard Library maintained by the Modelica Association.
Matrices.LU_solve2(LU, pivots, B);
This function call returns the solution X of the linear systems of equations
P*L*U*X = B;
where P is a permutation matrix (implicitly
defined by vector pivots
),
L is a lower triangular matrix with unit
diagonal elements (lower trapezoidal if m > n), and
U is an upper triangular matrix (upper trapezoidal if m < n).
The matrices of this decomposition are computed with function
Matrices.LU that
returns arguments LU
and pivots
used as input arguments of Matrices.LU_solve2
.
With Matrices.LU
and Matrices.LU_solve2
it is possible to efficiently solve linear systems
with different right hand side matrices. If a linear system of equations with
just one right hand side matrix shall be solved, it is
more convenient to just use the function
Matrices.solve2.
If a unique solution X does not exist (since the LU decomposition is singular), an exception is raised.
The LU factorization is computed with the LAPACK function "dgetrf", i.e., by Gaussian elimination using partial pivoting with row interchanges. Vector "pivots" are the pivot indices, i.e., for 1 ≤ i ≤ min(m,n), row i of matrix A was interchanged with row pivots[i].
Real A[3,3] = [1,2,3; 3,4,5; 2,1,4]; Real B1[3] = [10, 20; 22, 44; 12, 24]; Real B2[3] = [ 7, 14; 13, 26; 10, 20]; Real LU[3,3]; Integer pivots[3]; Real X1[3,2]; Real X2[3,2]; algorithm (LU, pivots) := Matrices.LU(A); X1 := Matrices.LU_solve2(LU, pivots, B1); /* X1 = [3, 6; 2, 4; 1, 2] */ X2 := Matrices.LU_solve2(LU, pivots, B2); /* X2 = [1, 2; 0, 0; 2, 4] */
LU |
Type: Real[:,size(LU, 1)] Description: L,U factors of Matrices.LU(..) for a square matrix |
---|---|
pivots |
Type: Integer[size(LU, 1)] Description: Pivots indices of Matrices.LU(..) |
B |
Type: Real[size(LU, 1),:] Description: Right hand side matrix of P*L*U*X=B |
X |
Type: Real[size(B, 1),size(B, 2)] Description: Solution matrix such that P*L*U*X = B |
---|