% 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
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
Ruslan Kashirov 2016년 2월 14일
OK Sorry it's my first time!

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2016년 2월 14일

1 개 추천

if all(Gamma(:)>0)
%they are all positive
end

댓글 수: 2

Ruslan Kashirov
Ruslan Kashirov 2016년 2월 14일
편집: Ruslan Kashirov 2016년 2월 14일
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Gamma Functions에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

질문:

2016년 2월 14일

댓글:

2016년 2월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by