[Linear Algebra 03] Display of elimination method and 4 solutions of AX=b

   This article is still a summary of the notes of the MIT course. Firstly, the elimination method is demonstrated, focusing on the process of transforming the matrix A into a row-simplified form, and then discussing the solutions of AX = b under different ranks r.


Elimination method display

   Still starting from an example, the known matrix A is:
A = [ 1 2 3 4 5 6 ] A = \begin{bmatrix} 1 &2 & 3 \\ 4 & 5 & 6 \end{bmatrix}A=[142536]

The first part AX =0

   Let's first consider the equation AX = 0 AX =0AX=0 , apply the elementary row transformation:
A = [ 1 2 3 4 5 6 ] ⇒ [ 1 2 3 0 − 3 − 6 ] ⇒ [ 1 2 3 0 1 2 ] ⇒ [ 1 0 − 1 0 1 2 ] = RA = \begin{bmatrix} 1 &2 & 3 \\ 4 & 5 & 6 \end{bmatrix} \Rightarrow \begin{bmatrix} 1 &2 & 3 \\ 0 & -3 & -6 \end{bmatrix} \Rightarrow \begin{bmatrix} 1 &2 & 3 \\ 0 &1 & 2\end{bmatrix} \Rightarrow \begin{bmatrix} 1 &0 & -1 \\ 0 & 1 & 2 \end{bmatrix} =RA=[142536][102336][102132][100112]=R We can find the identity matrix II
   in the row-reduced R matrixI , and the rest can be denoted asFFF. _ FollowAX = 0 AX=0AX=0 , we can easily find such a result,x 1 x_1x1and x 2 x_2x2is the row where the main column is located (that is, III ) corresponds to the unknown, whilex 3 x_3x3is a free variable, corresponding to FFF. _ If the following notation
X ( pivot ) = [ x 1 x 2 ] X ( free ) = [ x 3 ] X(pivot) = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix} \ \ \ X(free) = \begin{bmatrix} x_3 \end{bmatrix}X(pivot)=[x1x2]   X(free)=[x3]
   Then, corresponding toAX = 0 AX=0AX=0 can be written as:
[ IF ] [ X ( pivot ) X ( free ) ] = IX ( pivot ) + FX ( free ) = 0 \begin{bmatrix} I & F \end{bmatrix} \begin{bmatrix} X(pivot) \\ X(free) \end{bmatrix} =IX(pivot)+FX(free)=0[IF][X(pivot)X(free)]=IX(pivot)+FX(free)=After the 0
   shift, there is:
X ( pivot ) = − FX ( free ) X(pivot)=-FX(free)X(pivot)=F ree ( f ree )
   This is a very elegant formula in my opinion, that is to say, the solution of the original equation should have the following form:
x 1 = x 3 x 2 = − 2 x 3 x_1 = x_3 \\ x_2 = -2x_3x1=x3x2=−2x _ _3
   Use the rref function in matlab to get the reduced row echelon form under the Gauss-Jordan elimination method .

>> A = [1,2,3;4,5,6];
>> rref(A)

ans =

     1     0    -1
     0     1     2

   You can also use the solve function to verify the correctness of the solution .

>> syms x1;syms x2; syms x3;
>> result = solve([x1+2*x2+3*x3,4*x1+5*x2+6*x3]); % result作为struct存在
>> result.x1
 
ans =
 
x3
 
>> result.x2
 
ans =
 
-2*x3

The second part AX =b

    Let's take it a step further and consider AX = b AX=bAX=In the case of b , it is better to assume that column b is 7 and 8, so weconsider the augmented matrix of Aand apply elementary row transformation, that is,
[ 1 2 3 ∣ 7 4 5 6 ∣ 8 ] ⇒ [ 1 2 3 ∣ 7 0 − 3 − 6 ∣ − 20 ] ⇒ [ 1 2 3 ∣ 7 0 1 2 ∣ 20 / 3 ] ⇒ [ 1 0 − 1 ∣ − 19 / 3 0 1 2 ∣ 20 / 3 ] \begin{bmatrix} 1 &2 & 3 & | & 7 \\ 4 & 5 & 6 & | & 8\end{bmatrix} \Rightarrow \begin{bmatrix} 1 &2 & 3 & | & 7 \\ 0 & -3 & -6 & | & -20 \end{bmatrix} \Rightarrow \begin{bmatrix} 1 &2 & 3 & | & 7 \\ 0 & 1 & 2 & | & 20/3\end{bmatrix} \Rightarrow \begin{bmatrix} 1 &0 & -1 & | & -19/3 \\ 0 & 1 & 2 & | & 20/3\end{bmatrix}[14253678][102336720][102132720/3][10011219/320/3]
    So the solution is
x 1 = x 3 − 19 / 3 x 2 = − 2 x 3 + 20 / 3 x_1 = x_3-19/3 \\ x_2 = -2x_3+20/3x1=x319/3x2=−2x _ _3+20/3
    can also use the solve function to verify its correctness

>> syms x1;syms x2; syms x3;
>> result = solve([x1+2*x2+3*x3-7,4*x1+5*x2+6*x3-8]);  % 修改求解方程
>> result.x1
 
ans =
 
x3 - 19/3
 
>> result.x2
 
ans =
 
20/3 - 2*x3

solution discussion

    According to the example shown by the elimination method, we have already had a shallow understanding of the Gauss-Jordan elimination method to solve the equation. Next, we discuss the general solution situation, that is, AX = b AX = bAX=The solution of b under different ranks r, where A is am × nm\times nm×A general matrix of n . In matlab, the rank of a matrix can be obtained by using the rank function.

>> A = [1,2,3;4,5,6];
>> rank(A)

ans =

     2

Case 1: r = m < n

    In this case, the number of equations is less than the number of unknowns, so there must be infinitely many solutions. And at this time, since the rank of the matrix is ​​r, the number of free vectors is nr, which means that the solution space should be a hyperplane with dimension nr . Taking the example shown above as an example, the solution space at this time can be drawn as a 1-dimensional straight line in a 3-dimensional space. The illustration and code are as follows:Please add a picture description

% 解空间为n-r的超平面
% 定义
syms x1; syms x2;
y1 = x1+19/3; y2 = 10/3-0.0000001*x1-0.5*x2; % 避免默认将x2读成x1
% fsurf画平面
fsurf(y1,EdgeColor='g'); hold on; fsurf(y2,EdgeColor='b'); 
% 画交线
hold on;
fplot3(x1,-2*x1-6,x1+19/3,Color = 'r',Linewidth = 2)
% 标注
legend('x_1+19/3=x_3','10/3 - x_2/2=x_3','交线');
xlabel('x_1'); ylabel('x_2');zlabel('x_3');

Case 2: r = n < m

    In fact, take the transpose of A again to study
AT = [ 1 4 2 5 3 6 ] ⇒ [ 1 4 0 − 3 0 − 6 ] ⇒ [ 1 0 0 1 0 0 ] = [ I 0 ] = RA^ {T} = \begin{bmatrix} 1 &4 \\ 2 & 5 \\ 3 & 6 \end{bmatrix} \Rightarrow \begin{bmatrix} 1 &4 \\ 0 & -3 \\ 0 & -6 \end{ bmatrix} \Rightarrow \begin{bmatrix} 1 &0 \\ 0 & 1 \\ 0 & 0 \end{bmatrix} = \begin{bmatrix} I \\ 0 \end{bmatrix} =RAT= 123456 100436 100010 =[I0]=R
    can be found at this time, from the row to see,RRThe upper part of R is the identity matrixIII , the lower part is a 0 matrix. At this time, the number of equations is more than the number of unknowns, and the requirement for column b of the right-hand result item is actually put forward, that is, either satisfying ATA^TAA linear combination of the columns of T yields a particular solution; or there is no solution . For example, for the following equation, there is a special solution[ 1 , 1 ] T [1,1 ]^T[1,1]T
x 1 + 4 x 2 = 5 2 x 1 + 5 x 2 = 7 3 x 2 + 6 x 3 = 9 x_1+4x_2 = 5 \\ 2x_1 + 5x_2 = 7 \\ 3x_2+6x_3 = 9 x1+4x _2=52x _1+5 x2=73x _2+6x _3=9
   In other words,at this time column b can only be inATA^{T}AA certain vector in the column space where T is located will have a solution . In this case, the request is equivalent to the b column being located in the 3-dimensional spaceATA^TAT on the two-dimensional plane. You can also draw the corresponding diagram, the diagram and code are as followsPlease add a picture description

% b列所在的平面

% 画向量图
quiver3(0,0,0,1,2,3,'m'); hold on; quiver3(0,0,0,4,5,6,'black'); % 基底
hold on;  quiver3(0,0,0,5,7,9,'r');  % 满足条件的b
V1 = [1;2;3]; V2 = [4;5;6];
% 求法向量
Vn = cross(V1,V2);
% 画平面
syms x1;syms x2;syms x3;
plane = -(x1*Vn(1)+x2*Vn(2))/Vn(3);
hold on;
fsurf(plane);
% 标注
legend('基底列1','基底列2','满足条件的b','所在平面');
xlabel('b_1'); ylabel('b_2'); zlabel('b_3');

Case 3: r = n = m

   Intuitively, this will be a common part of the first two cases, so when the number of unknowns is equal to the number of equations, there will be one and only one solution . We can derive the general form of the solution, since r = n = mr = n = mr=n=m , so the square matrix is ​​invertible at this time. For the inverse of A on both sides of the equation:
AX = b ⇒ A − 1 AX = A − 1 b ⇒ IX = A − 1 b ⇒ X = A − 1 b AX=b \Rightarrow A^{-1}AX= A^{-1}b \Rightarrow IX=A^{-1}b \Rightarrow X=A^{-1}bAX=bA1AX=A1bIX=A1bX=A1 b
   Then there isa solution in the form ofA − 1 b A^{-1}bA1 b, and we can know thatRRR is equal to the unit matrixIII. _ Also give an example
B = [ 1 2 3 4 ] b = [ 5 6 ] B = \begin{bmatrix} 1 &2 \\ 3 & 4 \end{bmatrix} \ \ \ \ b= \begin{bmatrix} 5 \ \6 \end{bmatrix}B=[1324]    b=[56]
   then the calculation result is
X = B − 1 b = [ − 2 1 1.5 − 0.5 ] [ 5 6 ] = [ − 4 4.5 ] X = B^{-1}b= \begin{bmatrix} -2 & 1 \ \ 1.5 &-0.5\end{bmatrix} \begin{bmatrix} 5 \\ 6 \end{bmatrix}= \begin{bmatrix} -4 \\ 4.5 \end{bmatrix}X=B1b=[21.510.5][56]=[44.5]
   Use the solve function to verify correctness:

>> syms x1; syms x2;
>> result = solve([x1+2*x2-5,3*x1+4*x2-6]);
>> ans1 = result.x1,ans2 = result.x2
 
ans1 =
 
-4
 
 
ans2 =
 
9/2

Case 4: r < m, r < n

    This shows that there are linear correlations between columns and rows. From the previous derivation, we can easily know that the R matrix at this time should have the following form:
R = [ IF 0 0 ] R = \begin{bmatrix} I &F \ \0 & 0 \end{bmatrix}R=[I0F0]
    whenb = 0 b=0b=0 must have a solution 0, and whenb ≠ 0 b \ne 0b=When it is 0 , it needs to satisfy that column b should be in the column space where the matrix is ​​located.
[ IF 0 0 ] [ X ( pivot ) X ( free ) ] = [ X ( pivot ) + FX ( free ) 0 ] \begin{bmatrix} I &F \\ 0 & 0 \end{bmatrix} \begin{bmatrix} X(pivot) \\ X(free) \end{bmatrix} = \begin{bmatrix} X(pivot) +FX(free) \\ 0 \end{bmatrix}[I0F0][X(pivot)X(free)]=[X(pivot)+FX(free)0]
    That is,the mmof b needs to be satisfied at this timem rows havem − r mrmr line is the restrrWhen there is a linear combination of r rows, there will be solutions, and there are infinitely many solutions; otherwise, there will be no solutions. Of course, the expression of whether there is a solution condition is equivalent to the expression in the second case that the b column needs to be located in the column space where the matrix is ​​located.
    For example, modify the matrix B and the corresponding column b as
B = [ 1 2 2 4 ] b = [ 3 6 ] B = \begin{bmatrix} 1 &2 \\ 2 & 4 \end{bmatrix} \ \ \ \ b= \ begin{bmatrix} 3 \\ 6 \end{bmatrix}B=[1224]    b=[36]
    There is a solution at this time, and the solution can be[ 1 , 1 ] T [1,1 ]^T[1,1]T, [ 3 , 0 ] T [3,0 ]^T [3,0]T [ 0 , 1.5 ] T [0,1.5 ]^T [0,1.5]T and so on, the requirement for b can be recorded as a one-dimensional straight line b 2 = 2 b 1 b_2=2b_1in a two-dimensional planeb2=2 b1, and the solution space needs to satisfy x 2 = − 0.5 x 1 + 1.5 x_2=-0.5x_1+1.5x2=- 0.5 x1+1.5 , it is easy to find that these two spaces are exactly perpendicular to each other. The corresponding picture display and code are as follows:

Please add a picture description

% 解空间和b列所在空间

syms x1;
% b列所在的直线
fplot(2*x1);
% 解空间所在直线
hold on;
fplot(-x1/2+1.5);
% 标注
xlim([0,3.5]); ylim([0,3]);
% 求交点
hold on;
plot(0.6,1.2,'r+');
legend('b列所在的直线','解空间所在直线','交点(0.6,0.8)');


    Finally, use a table to sort out the number of understandings.

rank r number of solutions
r = m < n infinitely many solutions
r = n < m 0 solution or 1 solution
r = n = m 1 solution
r < m,r < n 0 solutions or infinitely many solutions

Guess you like

Origin blog.csdn.net/weixin_47305073/article/details/126086462