Solve a system of linear equations using this LU decomposition and the constant vector

Given the L and U decomposition of LU and the vector of constants b , such as LU*x=b , is there a built-in function that finds x ? So something like -

 X = functionName(L,U,b) 

Note that in L and U we are dealing with triangular matrices that can be solved directly by forward and reverse substitution without using a Gaussian elimination .

Edit:

The solution of this system of linear equations should be performed in accordance with the following steps -

 1. define y - st Ux=y 2. solve Ly=b by forward substitution 3. solve Ux=y by backward substitution 4. return y 

Edit 2:

I found linalg :: matlinsolveLU , but I have not tried it because I have too old version ( R2010a ). Does it work for someone?

+6
source share
2 answers

If you have:

 A = rand(3); b = rand(3,1); 

then the system solution can simply be calculated as:

 x = A\b 

Or, if you already have an LU decomposition A, then:

 [L,U] = lu(A); xx = U\(L\b) 

mldivide function is smart enough to detect that the matrix is โ€‹โ€‹triangular, and chose the algorithm accordingly (forward / reverse replacement)

+5
source

I think this is what you are looking for:

 A = rand(3,3); % Random 3-by-3 matrix b = rand(3,1); % Random 3-by-1 vector [L,U] = lu(A); % LU decomposition x = U\(L\b) % Solve system of equations via mldivide (same as x = A\b or x = (L*U)\b) err = L*U*xb % Numerical error 

The system of equations is solved using mldivide . You can also see qr , which implements QR decomposition instead of using LU decomposition. qr can directly solve problems like A*x = b and is more efficient. Also see linsolve . For symbolic systems, you can still use mldivide or try linalg :: matlinsolveLU in MuPAD.

+3
source

Source: https://habr.com/ru/post/946048/


All Articles