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 个评论
Image Analyst
2016-2-14
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
2016-2-14
回答(1 个)
Walter Roberson
2016-2-14
if all(Gamma(:)>0)
%they are all positive
end
2 个评论
Ruslan Kashirov
2016-2-14
编辑:Ruslan Kashirov
2016-2-14
Walter Roberson
2016-2-14
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
类别
在 帮助中心 和 File Exchange 中查找有关 Gamma Functions 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!