Can my code be written like this?

i want to write this formula as code in matlab,but i am not very sure that is my code right.
The range of j and k are both 1~K
for k= 1:K
for j=1:K
if k==j
a=mu(k).*( abs(h_(k)'*f_(k)^2 ) / hat_r(k);
else
b=mu(k).*( abs(h_(k)'*f_(j)^2 );
end
end
total=a+b;
end

댓글 수: 5

Walter Roberson
Walter Roberson 2019년 1월 31일
No, your are overwriting b for every iteration of for j except the k==j case, and you are not totalling those b cases.
yang-En Hsiao
yang-En Hsiao 2019년 1월 31일
can you show me your modification? thx a lot
Walter Roberson
Walter Roberson 2019년 1월 31일
It is not obvious to me what K_k is
Jan
Jan 2019년 1월 31일
편집: Jan 2019년 1월 31일
Neither the elementwise .* does not matter, when you work with scalars. Using conj looks less confusing than using the transposition.
In abs(h_(k)'*f_(k)^2) you are squaring f only. Use this instead:
abs(conj(h_(k)) * f_(k))^2
yang-En Hsiao
yang-En Hsiao 2019년 1월 31일
K_k means that the range of j is the same as k,that is 1 ~K.but j can't not be equal to k

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

답변 (1개)

Jan
Jan 2019년 1월 31일
편집: Jan 2019년 1월 31일

0 개 추천

There is no "hat_r(k)" in your formula. A trailing parenthesis is missing also.
total = 0;
hc = conj(h_);
for k = 1:K
c1 = ;
sumj = 0;
for j = 1:K
if j ~= k % [EDITED]
sumj = sumj + abs(hc(k) * f_(j)) ^ 2;
end
end
total = total + mu(k) * (abs(hc(k) * f_(k)) ^ 2 - sumj) / r_hat(k);
end

댓글 수: 2

yang-En Hsiao
yang-En Hsiao 2019년 1월 31일
it should be bar_r(k).there is a bar_r(k) ,1.,in the picture.
and the 2 means that the range of j is the same as k,that is 1 ~K.but j can't not be equal to k
不等於.PNG
Jan
Jan 2019년 1월 31일
편집: Jan 2019년 1월 31일
If "it" should be "bar_r(k)", than simply insert this in my code. You do not have to wait until I do it. By the way, the character is a greek "gamma", not an "r". But names do not matter.
There is still a missing closing parenthesis. Please post a valid formula. A smaller zoom-level would be nice.

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

카테고리

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

태그

질문:

2019년 1월 31일

편집:

Jan
2019년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by