一般想法
我一直在做一个线性代数项目,其中的想法是测试一组给定的向量(矩阵)是否线性依赖/独立。为此,下一个程序接收一个名为 value 的矩阵(用户输入/MxN),并为标准进行第一次传递(这部分没有问题),接下来如果向量是线性依赖的,它必须测试内部向量之间是否有一些 LI/LD 子集,为此它开始迭代行的排列并为其制定标准, 如果这导致 LI 子集,则必须绘制向量和由向量形成的空间。即使初始矩阵的大小为 MxN,矩阵通常也预期为 2 或 3 列,R2 或 R3)。
问题
在第二遍中,一旦系统被标记为线性依赖,系统就会重叠相同窗口中的图形,期望的输出将是进行第一次通过,如果系统是LD,则显示初始图形,然后开始在单独的窗口中绘制排列矩阵的图形。
NewMatrix 遍历原始"值"矩阵,并不断形成行/向量的排列以再次检查标准(确实如此,但在同一窗口中)。请注意,初始矩阵"值"由用户定义,并且应该已经在显示的代码的起点输入。
法典
RangS=rank(R) //LI or ld criterion
[r, c] = size(value)
if (rank(value))==r
set(handles.text3,'String',('System>LI'));
figure(3);
hold on;
z = zeros(size(value, 1), 1);
quiver3(z, z, z, value(:, 1), value(:, 2), z, 0);
grid on
view(45, 45);
s=sum(value);
quiver3(0,0,0,s(1),s(2),0,'r');
points=[X' Y'];
else
set(handles.text3,'String',('System>LD'));
figure(3); //this graph should be done apart
hold on;
z = zeros(size(value, 1), 1);
quiver3(z, z, z, value(:, 1), value(:, 2), z, 0);
grid on
view(45, 45);
points=[X' Y'];
for jj = 1:size(value,1)-1 //here starts permuting vectors>credits to MikeLimaOscar
for kk = jj+1:size(value,1)
NewMatrix= value([jj,kk],:)
F=rref(NewMatrix);
RangS=rank(R) //the same criterion applied to the permutated matrices
[r, c] = size(NewMatrix)
if (rank(NewMatrix))==r
set(handles.text3,'String',('Subsystem :LI'));
figure(3); there should be one graph for every permutated matrix
hold on;
z = zeros(size(NewMatrix, 1), 1);
quiver3(z, z, z, NewMatrix(:, 1), NewMatrix(:, 2), z, 0);
grid on
view(45, 45);
s=sum(NewMatrix);
quiver3(0,0,0,s(1),s(2),0,'r');
points=[X' Y'];
else
set(handles.text3,'String',('Subsystem:LD'));
figure(3);
hold on;
z = zeros(size(NewMatrix, 1), 1);
quiver3(z, z, z, NewMatrix(:, 1), NewMatrix(:, 2), z, 0);
grid on
view(45, 45);
points=[X' Y'];
end
end
end
end
- 您正在同一窗口 [
figure(3)
] 上绘制所有图形。 - 提供不同的参数来计算可以解决问题。
每个窗口的特定索引
Permutation(jj) |Permutation 1 | Permutation 2 | Permutation 3
____________________________________________________________________
|[1]submatrix 1 | [4]submatrix 1 |[6]submatrix 1
submatrix(kk) |[2]submatrix 2 | [5]submatrix 2 |[7]submatrix 2
|[3]submatrix 3 | |[8]submatrix 3
| | |[9]submatrix 4
____________________________________________________________________
Last index | 3 | 5 | 9
____________________________________________________________________
括号中的索引将用作图形参数
Permutation 1
,只需使用子矩阵索引kk
,index_1 = kk
Permutation 2
,使用子矩阵索引kk
和Last index
子矩阵
的排列
1
index_2 = Last index(Permutation 1) + kk
Permutation 3
,使用子矩阵索引kk
和Last index
子矩阵的置换2
index_3 = Last index(Permutation 2) + kk
泛化,来自第一个排列的一部分,第 n 个排列中的索引为
index_n = Last index(Permutation n-1)) + kk
对于给定的问题total of submatrices
给定Permutation jj
可以计算为
total(Permutation jj) = numel(jj+1:size(value,1))
请通读评论
% Check if the entire matrix is linear independent or not
if LI
% Linear independent
% Plot the graph in window #1
figure(1)
else
% Linear dependent
% Plot the graph in window #1
figure(1)
% Starting index for next Permutation
Last_index = 0;
% Figure() argument initialization
index = 0;
% Permutation begins here
for jj = 1:size(value,1)-1
% submatrices for a given permutation jj begins here
for kk = jj+1:size(value,1)
% Check if submatrix is linear independent or not
if submatrix(kk) from permutation (jj) is LI
% Linear independent
% Plot the graph in window #index
index = Last_index + kk
figure(index)
else
% Linear dependent
% Plot the graph in window #index
index = Last_index + kk
figure(index)
end
% End of checking if submatrix is linear independent or not
end
% Update last index for the next permutation starting index
Last_index = Last_index + numel(jj+1:size(value,1))
% End of submatrices for a given permutation jj
end
% End of Permutation
end
% End of checking if the entire matrix is linear independent or not