According to the basic knowledge of solving equations in linear algebra, we should first judge whether the rank of the coefficient matrix is equal to the rank of the augmented matrix. If there is no solution, if there is a solution, according to the relationship between the rank and the number of unknown quantities, the judgment is the only solution or the infinite solution, and if it is infinitely many solutions, the general solution of the homogeneous equations is added the special solution of the homogeneous equation group.
To obtain the special solution of the ax=b of the nonhomogeneous linear equation Group, we can use the command a\b directly to solve the general solution of the homogeneous linear equation group, and use the function null or rref to realize it.
Command |
meaning |
B = null (A, ' R ') |
The ax=0 of the homogeneous linear equation set with a coefficient matrix of a, the result is a rational number, and the column vector of B is the column vector of the fundamental solution system. |
Z = null (A) |
After finding the basic solution system of ax=0, the orthogonal unit of the fundamental solution system is obtained and stored in Z |
C = Rref (A) |
To find the most simple matrix of matrix A (reduced row echelon form) |
function [S_h, s_p] = Solvels (a,b)
% input parameter A: coefficient matrix
% input parameter b:ax=b constant Item column vector b
% S_h: The basic solution system of homogeneous linear equation group
% s_ P: A special solution of the nonhomogeneous linear equation Group
if size (a,1) ~= length (b) %size (a,1) to find the row number of the matrix error
(' Input data errors, please re-enter. ');
return;
else
B = [A,b]; % augmented matrix
rank_a = rank (A); % to calculate the rank
Rank_b = rank (B) of the coefficient matrix; % the rank
if rank_a ~= rank_b% of the augmented matrix is no solution
disp (' linear equation Group has no solution. ');
S_h = [];
s_p = [];
else if Rank_b = = Size (a,2) if the rank = unknown number
%size (a,2) of the augmented matrix asks for the number of columns in the matrix, the equivalent of length (a)
disp (' linear equation Group has unique solution. ');
s_p = a\b; % seek unique solution
s_h = [];
else
disp (' linear equation Group has infinite solution. ');
S_h = null (A, ' r ');% to find the basic solution of homogeneous equations
s_p = a\b; % to seek the special solution end end of a homogeneous equation group
example using MATLAB to solve equations
⎧⎩⎨x1+2x2−2x3+3x4=22x1+4x2−3x3+4x4=55x1+10x2−8x3+11x4=12 \begin{cases} x_1+2x_2-2x_3+3x_4=2 \ 2x_1+4x_2-3x_3+4x_4 =5 \ 5x_1+10x_2-8x_3+11x_4=12 \end{cases}
A=[1 2-2 3; 2 4-3 4; 5 10-8 one];
B=[2 5] '; format rat;
[S_h, S_p]=solvels (a,b)
Run results
There are infinite solutions to the systems of linear equations.
S_h =
-2 1
1 0 0 2 0 1
s_p =
0
7/4
0
-1/2
The linear equation Group has infinitely many solutions, the general solution is
X=k1⎛⎝⎜⎜⎜−2100⎞⎠⎟⎟⎟+k2⎛⎝⎜⎜⎜1021⎞⎠⎟⎟⎟+⎛⎝⎜⎜⎜07/40−1/2⎞