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
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?
Walter Roberson
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 ExchangeGamma 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