Help me write out the code of a mathematical formula

1 次查看(过去 30 天)
Hi Everyone
Please, i need someone to help me write out the code of the mathematical formula below. Since i cannot type out the notations on this page, i have written it out in words. I await your response...Thanks
h(subscript 11)=1*1e-6;
h(subscript 12)=0.9*1e-6;
h(subscript 21)=1.1*1e-6;
h(subscript 22)=1.3*1e-6;
H=[h(subscript 11) h12;h21 h22];
beta (subscript 1)= 0.7
beta (subscript 2)=0.7
P(subscript 1)=1;
P(subscript 2)=1;
K=1:2
for i=1:K
Noise=summation (on top of the sigma notation is K and below is j=1 j not equal to i) = |h(subscript ji)|^2 * P(subscript j)+beta(subscript i)

回答(1 个)

Walter Roberson
Walter Roberson 2011-4-14
Based upon what you have written:
H = [1E-6 0.9E-6; 1.1E-6; 1.3E-6];
beta = [0.7 0.7];
P = [1 1];
K = 2
for i = 1:K
j = 3-i;
Noise = H(j,i).^2 * P(j) + beta(i);
end
Unfortunately this will not produce a useful answer. Either the summation has to appear outside of the K and i definitions or the Noise has to be subscripted.
The magnitude bars that you show around h(subscript ji) are a waste if you are going to be immediately squaring the value, unless the h values can turn out to be complex valued... or there is a flaw in the transcription of the notation.
You may have noticed that I did not include any summation, and I did not include anything for the K=1 case. With the limits you have defined for the size of H, if K is 1 and i is 1 to K then i is 1 to 1, and then the sum over j=1 to K with j not equal to i would be the sum over j = 1 to 1 with j not equal to i, but i is constrained to 1 so this would be j = 1 to 1 excluding 1 which is the empty case. There is thus no value when K is 1, so there is no point including K=1.
When K is 2 then i is 1 or 2, and j = 1 to 2 excluding i forces j to be the single value that is opposite to i -- j being 2 when i is 1 and j being 1 when i is 2. That can be calculated with no conditionals as j = 3 - i
Then you define Noise inside the loop, but you don't do anything with the calculated value, so the final value will be the same as if you had only executed the loop once with its final loop index.
You could further optimize the code I show and turn it in to a single constant assignment Noise = (0.9*1e-6)^2 + 0.7 which would be so close to 0.7 that you would have to look hard to see the difference.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by