Matlab realization of algorithm
Afficher commentaires plus anciens
% 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 commentaires
Image Analyst
le 14 Fév 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
le 14 Fév 2016
Réponses (1)
Walter Roberson
le 14 Fév 2016
if all(Gamma(:)>0)
%they are all positive
end
2 commentaires
Ruslan Kashirov
le 14 Fév 2016
Modifié(e) : Ruslan Kashirov
le 14 Fév 2016
Walter Roberson
le 14 Fév 2016
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
Catégories
En savoir plus sur Gamma Functions dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!