Write matlab code for the following algorithm

1 次查看(过去 30 天)
I have this algorithm
I write this code for my example
A = [10 -10; 1 0; -1 0; 0 -1 ; 0 1; 11 -10; -1 -1];
C = cov(A).^(-1/2).*A;
M = size(A,1);
omega = C*C';
x0=[];x1=[];x2=[];PS=[];
for i0=1:M
for i1=1:M
for i2=1:M
j = 0;
if isequal(i2,i1)
x2(j) = abs(omega(i1,i0)+omega(i2,i0));
j = j+1;
end
end
x1(j) = min(median(x2,'all')); % lower median
end
x0(j) = 1.1 .* min(median(x1,'all')); % lower median
end
for i3=1:M
PS(i3) = max(omega(i3)/x0);
end
but the above-mentioned code has many problems. I do not know how to fix it.
the result should be
PS = [16.77;0.839;0.839;0.839;0.839;17.609;1.677];

采纳的回答

Karim
Karim 2022-8-11
编辑:Karim 2022-8-11
I'm not familiar with the algoritm, so it could still have some mistakes left...
However, i was able to identify a couple of mistakes:
  • x1 should be indexed with i1 and x0 with i0
  • you first need to update j before you can use it as an index into x2
  • the condition states that you should enter if i2 is not equal to i1
  • i'm guessing that the matrix A you provided does not have the correct dimensions, i assume it should be a 7x7 matrix?
  • also min( median( ) ) is not the same as the low median, since x2 is a vector the median will return a scalar
Below i used an random A matrix, hence the 'PS' result is not the same as the one you expect. Where did you obtain the matrix A and the expected result?
A = [10 -10; 1 0; -1 0; 0 -1 ; 0 1; 11 -10; -1 -1];
% use a random A matrix...
A = rand(7) * 100;
C = cov(A)^(-1/2) * A;
M = size(A,1);
omega = C*C';
x0 = zeros(M ,1);
x1 = zeros(M ,1);
x2 = zeros(M-1,1); % 1 element less since we neglect the case where i2 == i1
PS = zeros(M ,1);
for i0 = 1:M
for i1 = 1:M
j = 0;
for i2 = 1:M
if i2 ~= i1
j = j + 1;
x2( j ) = abs( omega(i1,i0) + omega(i2,i0) );
end
end
x1( i1 ) = median(x2,'all');
end
x0( i0 ) = 1.1 * median(x1,'all');
end
for i3 = 1:M
PS(i3) = max( omega(i3)/x0 );
end
PS
PS = 7×1
0.2077 0 0.3258 0.2614 0.4130 0 0
  1 个评论
NA
NA 2022-8-11
编辑:NA 2022-8-11
Thank you for your time.
C = cov(A)^(-1/2) * A
the above line means that we normalize the A matrix by its covariance
covariance here is R = eye( M )

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by