Matlab realization of algorithm

% water pouting algorithm
Mt=2;
Mr=2;
SNR=2;
P=1; %iteration count
negative=0;
samples=10;
for i=1:1:samples;
Hw(:,:,i) = (randn(2,2)+1i*randn(2,2))/sqrt(2);
end
sigma_N_square=10^(-(SNR/10));
RANK=rank(Hw(:,:,1));
sum_lambda=0;
for r=1:1:RANK;
lambda(:,1) = eig(Hw(:,:,1)*Hw(:,:,1)');
sum_lambda = sum_lambda+1/lambda(r,1);
end
Mu = 1/(RANK-(P-1)) * ( Mt + Mt*sigma_N_square/(P*sum_lambda) );
if
for j=1:1:(RANK-(P-1)); % checking non-negative Gammas
Gamma(:,j) = Mu - Mt * sigma_N_square/ (P * lambda(j,1) );
end
Question - How do I realize during all algorithm checking the elements of the Gamma matrix (are they positive if no go back in the beginning of algorithm and increase P=P+1 and find elements of Gamma again and so on. My goal is to get all Gammas being positive)

2 comentarios

Image Analyst
Image Analyst el 14 de Feb. de 2016
I'll do it for you this time, but for the future, learn how to format your code here: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Your "if" statement at the end does not have a condition, or an end statement, so that won't work.
Ruslan Kashirov
Ruslan Kashirov el 14 de Feb. de 2016
OK Sorry it's my first time!

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 14 de Feb. de 2016
if all(Gamma(:)>0)
%they are all positive
end

2 comentarios

Ruslan Kashirov
Ruslan Kashirov el 14 de Feb. de 2016
Editada: Ruslan Kashirov el 14 de Feb. de 2016
Thank you!
But how can i return to beginning of the algorithm after the checking the elements of Gamma? Is there any analogue of the command "goto" in Matlab?
However, the recommended method would be instead to use
while true
... do something
if all(Gamma(:)>0)
break; %we succeeded, we can leave the loop!
end
end

Iniciar sesión para comentar.

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 14 de Feb. de 2016

Comentada:

el 14 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by