.Modelica.Math.Matrices.LU_solve2

Information

Syntax

Matrices.LU_solve2(LU, pivots, B);

Description

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].

Example

  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] */

See also

Matrices.LU, Matrices.solve2,

Interface

function LU_solve2
  extends Modelica.Icons.Function;
  input Real LU[:, size(LU, 1)] "L,U factors of Matrices.LU(..) for a square matrix";
  input Integer pivots[size(LU, 1)] "Pivots indices of Matrices.LU(..)";
  input Real B[size(LU, 1), :] "Right hand side matrix of P*L*U*X=B";
  output Real X[size(B, 1), size(B, 2)] "Solution matrix such that P*L*U*X = B";
end LU_solve2;

Generated at 2020-06-05T07:38:22Z by OpenModelica 1.16.0~dev-420-gc007a39