Write matlab code for the following algorithm

1 visualizzazione (ultimi 30 giorni)
NA
NA il 11 Ago 2022
Modificato: NA il 11 Ago 2022
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];

Risposta accettata

Karim
Karim il 11 Ago 2022
Modificato: Karim il 11 Ago 2022
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 Commento
NA
NA il 11 Ago 2022
Modificato: NA il 11 Ago 2022
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 )

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by