Various decompositions of matrices

1. LU decomposition

    It has been proved in linear algebra that if the square matrix is ​​non-singular, that is, the determinant of is not 0, the LU decomposition always exists, and its form is:

     \begin{bmatrix} a_{11}& a_{12}& \cdots & a_{1n}\\ a_{21}& a_{22}& \cdots & a_{2n}\\ \vdots & \vdots & \ddots & \vdots \\ a_{n1}& a_{n2}& \cdots & a_{nn} \end{bmatrix}=\begin{bmatrix} 1& 0& \cdots & 0\\ l_{21}& 1& \cdots & 0\\ \vdots & \vdots & \ddots & \vdots \\ l_{n1}& l_{n2}& \cdots & 1 \end{bmatrix}\begin{bmatrix} u_{11}& u_{12}& \cdots & u_{1n}\\ 0& u_{22}& \cdots & u_{2n}\\ \vdots & \vdots & \ddots & \vdots \\ 0& 0& \cdots & u_{nn} \end{bmatrix}

    For example, for a fourth-order matrix, it can be decomposed into:

    \begin{bmatrix} a_{11} & a_{12} & a_{13} & a_{14} \\ a_{21} & a_{22} & a_{23} &a_{24} \\ a_{31} & a_{32} & a_{33} & a_{34}\\ a_{41} &a_{42} &a_{43} &a_{44} \end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ l_{21} & 1 & 0 &0 \\ l_{31} & l_{32} & 1} & 0\\ l_{41} &l_{42} &l_{43} &1 \end{bmatrix}\begin{bmatrix} u_{11} & u_{12} & u_{13} & u_{14} \\ 0 & u_{22} & u_{23} &u_{24} \\0 & 0 & u_{33} & u_{34}\\ 0 &0 &0 &u_{44} \end{bmatrix}=\begin{bmatrix} u_{11} & u_{12} & u_{13} & u_{14}\\ l_{21}u_{11}& l_{21}u_{12}+u_{22}&l_{21}u_{13}+u_{23} & l_{21}u_{14} +u_{24} \\ l_{31}u_{11}&l_{31}u_{12} + l_{32}u_{22} &l_{31}u_{13}+l_{32}u_{23}+u_{33} &l_{31}u_{14}+l_{32}u_{24}+u_{34}\\ l_{41}u_{11}&l_{41}u_{12}+l_{42}u_{22} &l_{41}u_{13}+l_{42}u_{23}+l_{43}u_{33} &l_{41}u_{14}+l_{42}u_{24}+l_{43}u_{34} + u_{44} \end{bmatrix}

 Find the pattern:

  • The first row has no dependent factors, so it can be directly concluded that the first column only depends on the first row, so after the first row is obtained, the first column can also be calculated.
  • In the same way, the second main row is the same. You can calculate the main row first, and then calculate the main column, which is calculated in the order of the solid line first, and then the dotted line as shown in the figure below.
  • Observe carefully, in fact, as long as the main diagonal element of the U matrix is u_ {ii}calculated first, it does not matter whether the row or the column is calculated first, because the unknown lu element of the corresponding row and column does not depend on other parameters.
  • Each element in the original matrix a_{ij}is used only once. u_ {ij}After the corresponding one is calculated , its information has been diffused into the entire calculation structure and can be discarded. Subsequent calculations are no longer dependent. For computer program calculations, the advantage is to optimize the memory of the algorithm and provide a grip.  

According to the law found above, try to derive the calculation formula as follows:

Combine linearly according to the line of U

Row_1(A)=1*Row_{1}(U) +0*Row_2(U)+\cdots+0*Row_n(U) = Row_1(U)

get:

\\Row_1(A) = Row_1(U)\Rightarrow u_{1j} = a_{1j}, \qquad j=1,2,\cdots,n

In addition, according to the linear combination of the columns of L

\\Colum_1(A)=u_{11}*Colum_{1}(U) +0*Colum_2(U)+\cdots+0*Colum_n(U) = u_{11}Colum_1(U)\Rightarrow l_{i1}=\frac{a_{i1}}{u_{11}},\qquad i=2,3,\cdots,n 

So get:

\left\{\begin{matrix} u_{1j} = a_{1j}, \qquad j=1,2,\cdots,n\\ \\ l_{i1}=\frac{a_{i1}}{u_{11}},\qquad i=2,3,\cdots,n\end{matrix}\right.

 For the inner matrix, because of i>jtime  ,, u_ {ij} == 0so, in order to find u_{ij}, i>1,j\geqslant ithe value of time, you can calculate:

\\a_{ij} = l_{i1}u_{1j}+l_{i2}u_{2j}+\cdots+l_{i,i-1}u_{i-1, j}+1\cdot u_{ij} \quad u_{1j},u_{2j},\cdots,u_{i-1, j}, l_{i1}, l_{i2},\cdots, l_{i, i-1} \ are \ known.

and so:

\\u_{ij} = a_{ij}-\sum_{s=1}^{i-1}l_{is}u_{sj}, \qquad i > 1, j \geqslant i

Because of the i< jtime  l_{ij}==0,, so, in order to find l_{ij}, j>1,i> jthe value of time, you can calculate:

\\ a_ {ij} = l_ {i1} u_ {1j} + l_ {i2} u_ {2j} + \ cdots + l_ {i, j-1} u_ {j-1, j} + l_ {ij} u_ {jj} \ quad u_ {1j}, u_ {2j}, \ cdots, u_ {j, j}, l_ {i1}, l_ {i2}, \ cdots, l_ {i, j-1} \ are \ known .

\\l_{ij} = (a_{ij}-\sum_{s=1}^{j-1}l_{is}u_{sj})/u_{jj}, \qquad j > 1, i > j

So, get:

\left\{\begin{matrix} u_{1j} = a_{1j}, \qquad j=1,2,\cdots,n\\ \\ l_{i1}=\frac{a_{i1}}{u_{11}},\qquad i=2,3,\cdots,n\end{matrix}\right.

\\ \left\{\begin{matrix} u_{ij} = a_{ij}-\sum_{s=1}^{i-1}l_{is}u_{sj}, \qquad \qquad i > 1, j \geqslant i \\ \\ \\ l_{ij} = (a_{ij}-\sum_{s=1}^{j-1}l_{is}u_{sj})/u_{jj}, \qquad j > 1, i > j \end{matrix}\right.

According to the above two formulas, coding on octave is realized as:

% find the LU factorization of the matrix
% input:
%   a: the matrix need to be factorize
%   n: the number of the low or column in the matrix
% output:
%   no output
function LU(a,n)
    m=eye(n);    %genernate the unit matrix.
    for j = 1 : n-1
        if abs(a(j,j))<eps; 
            error('zero pivot encountered');    % when the zero pivot happens,end the process
        end
        for i = j+1 : n
            mult = a(i,j)/a(j,j);
            m(i,j) = mult;  
            for k = j:n
                a(i,k) = a(i,k) - mult*a(j,k);
            end
        end
    end
disp('  L=');  disp(m);
disp('  U=');  disp(a);
disp('  LU='); disp(m*a);          % to check if the result is right

The result of the operation is:

The above program requires that each order of the matrix is ​​not 0, otherwise the program will report an error. E.g:

This problem has time to be fixed.


end!

Guess you like

Origin blog.csdn.net/tugouxp/article/details/112553279