MATLAB 中的简化行梯形 (rref) 矩阵
矩阵的缩减行梯形形式用于查找矩阵的秩,并进一步允许求解线性方程组。矩阵是行梯队形式,如果
- 所有仅由零组成的行都在底部。
- 非零行的第一个非零元素始终严格位于其上方行的第一个非零元素的右侧。
例子 :
一个矩阵可以有多个行梯队形式。矩阵是缩减行梯队形式,如果
- 它是排梯队形式。
- 每个非零行中的第一个非零元素是 1。
- 包含非零为 1 的每一列在其所有其他条目中都有零。
例子:
其中 a1,a2,b1,b2,b3 是非零元素。
一个矩阵有一个 独特的缩减行梯队形式。 Matlab 允许用户使用 rref() 方法找到缩减行梯队形式。 rref() 的不同语法是:
- R = rref(A)
- [R,p] = rref(A)
让我们详细讨论上述语法:
参考文献(A)
它使用Gauss-Jordan方法返回矩阵A的缩减行梯形形式。
Matlab
% creating a matrix using magic(n)
% generates n*n matrix with values
% from 1 to n^2 where every row sum
% is equal to every column sum
A = magic(4);
disp("Matrix");
disp(A);
% Reduced Row Echelon Form of A
RA = rref(A);
disp("rref :");
disp(RA);
Matlab
% creating a matrix using magic(n)
% generates n*n matrix with values
% from 1 to n^2 where every row sum
% is equal to every column sum
A = magic(5);
disp("Matrix");
disp(A);
% Reduced Row Echelon Form of A
[RA,p] = rref(A);
disp("rref :");
disp(RA);
% Displaying pivot vector p
disp("Pivot vector");
disp(p);
Matlab
% Coefficient matrix
A = [1 1 1;
1 2 3;
1 4 7];
% Constant matrix
b = [6 ;14; 30];
% Augmented matrix
M = [A b];
disp("Augmented matrix");
disp(M)
% Reduced Row echelon form of
% Augmented matrix
R = rref(M);
disp("rref");
disp(R)
输出 :
参考文献(A)
- 它返回简化行阶梯表R和枢轴p的矢量
- p是一个行号向量,在其缩减行梯队形式中具有一个非零元素。
- 矩阵 A 的秩是 length(p)。
- R(1:length(p),1:length(p)) (R 中的第一个 length(p) 行和 length(p) 列)是一个单位矩阵。
MATLAB
% creating a matrix using magic(n)
% generates n*n matrix with values
% from 1 to n^2 where every row sum
% is equal to every column sum
A = magic(5);
disp("Matrix");
disp(A);
% Reduced Row Echelon Form of A
[RA,p] = rref(A);
disp("rref :");
disp(RA);
% Displaying pivot vector p
disp("Pivot vector");
disp(p);
输出 :
使用缩减行梯队形式寻找线性方程组的解:
线性方程组是
系数矩阵A 是
常数矩阵B 是
那么增广矩阵[AB] 是
MATLAB
% Coefficient matrix
A = [1 1 1;
1 2 3;
1 4 7];
% Constant matrix
b = [6 ;14; 30];
% Augmented matrix
M = [A b];
disp("Augmented matrix");
disp(M)
% Reduced Row echelon form of
% Augmented matrix
R = rref(M);
disp("rref");
disp(R)
输出 :
那么简化的方程是
它有无限的解,一个可以是 .