我想组织这些结果并以某种方式跟踪它们。我不知道如何坚持下去,直到达到2号矩阵。还有一种更好的方式可以做我想做的事,这会让我很开心。
编辑:我希望能够从更多级别的递归中看到结果。问题是我不知道如何将结果从10级发送到第一级,以便它可以用于整个程序。此外,我不确定我是否可以跟踪它们,以了解每个结果的所有I的所有值,也就是说删除了哪些行/列。
clc
close all
clear all
fclose('all');
d2=[0 -1.165 -3.5493 -2.3828 -1.1464
1.165 0 -2.3843 -1.2178 0.0186
3.5493 2.3843 0 1.1665 2.4029
2.3828 1.2178 -1.1665 0 1.2364
1.1464 -0.0186 -2.4029 -1.2364 0];
[a,f] = smaller(d2, 0);
function [e,next] = smaller(d, level)
[Rows,~] = size(d);
level = level + 1;
for i = 1 : Rows
d_s = d;
d_s(i,:) = [];
d_s(:,i) = [];
e(i,1) = s2a(eig(d_s));
if nnz(d_s) > 11
[next(:,i)] = smaller(d_s, level);
end
end
end
function f = s2a(u)
Rows = size(u);
f = 0;
for i = 1 : Rows
f = f + u(i)*u(i);
end
end
所有较小5x5矩阵的结果是:
-31.6632098200000
-56.5056698200000
-22.7225231200000
-53.4562986200000
-56.3222738200000
适用于所有较小的4x4:f
-17.3266712400000 -17.3266712400000 -6.02413552000000 -22.9183217200000 -17.0572911600000
-6.02413552000000 -17.0413075200000 -17.0413075200000 -39.3713837200000 -39.2719771600000
-22.9183217200000 -39.3713837200000 -5.34360784000000 -5.34360784000000 -17.0359953600000
-17.0572911600000 -39.2719771600000 -17.0359953600000 -39.2792839600000 -39.2792839600000
我想要所有较小矩阵的所有结果,以及组织它们的方法。
所以我最终在提取数据后离开了组织:
function [e] = smaller(d)
[Rows, ~] = size(d);
e(1, 1) = 0;
for i = 1 : Rows
d_s = d;
d_s(i,:) = [];
d_s(:,i) = [];
e(end+1, 1) = s2a(eig(d_s));
if nnz(d_s) > 2
[next] = smaller(d_s);
[rows2, ~] = size(next);
e(end+1:end+rows2, 1) = next;
end
end
end
这些是值,总有一天我会重新排列它们:
value nr of rows/cols deleted
-31.6632 1
-17.3266 2
-3.05736 3
-11.5478 3
-2.72144 3
-6.02413 2
...........
我发现了另一种更快的方法:
S=dec2bin(1:2^size(d1,1)-1)=='1';
b=cell(size(S,1),1);
for ix=1:size(S,1)
b{ix}=d1(find(S(ix,:)),find(S(ix,:)));
if isempty(b{ix})<1
e(ix,1)=s2a(eig(b{ix}));
end
end