complex equation with summation

I am required to implement this equation in matlab
and here is what i have come up with
i1 = 0;
i1 = ((0.5*(1-(sqrt((g*gamma)/(m+(g*gamma))))))^LM)*s;
s=0;
for k=0:LM-1
s=s+(nchoosek(2*k,k)*(1/((4*((mu^2)+1))^k)));
end
is my code correct?

답변 (2개)

Geoff Hayes
Geoff Hayes 2014년 7월 2일

0 개 추천

Sam - have you tried executing this equation to see what it will produce, comparing the results against some known input-output pairs?
In the above code, the i1 calculation comes before the s which could have just been a copy and paste ordering mistake but the latter must come before the former since i1 depends on s.
I'm assuming that m, g, LM, and gamma are constants. Note that in MATLAB R2014a, gamma is a built-in function (see http://www.mathworks.com/help/matlab/ref/gamma.html). You should avoid naming variables after built-in functions so please rename gamma to gammaVal.
While the i1 calculation looks correct, the code for s is very different from the equation.
The
nchoosek(2*k,k)
should be
nchoosek(LM-1+k,k)
and the
(1/((4*((mu^2)+1))^k))
should be
(0.5*(1+sqrt(g*gammaVal/(m+g*gammaVal))))^k
Did you perhaps mix up the calculation of s with another equation?
Sam
Sam 2014년 7월 3일
편집: Sam 2014년 7월 3일

0 개 추천

thanks for the corrections, i have made the changes. this is what i am trying to solve
where I1 and I2 are replaced by
and
here is the complete code that i have come up with
function ber = var(gamma)
M = 64;
m = 1;
g = 3/(2*(M-1));
LM = 2;
mu = sqrt((g*gamma)/m);
alpha = sqrt((g*gamma)/(m+(g*gamma)));
beta = sqrt((g*gamma)/(m+(g*gamma)));
s=0;
for k=0:LM-1
s=s+(nchoosek((LM-1+k),k)*((0.5*(1+(sqrt((g*gamma)/(m+(g*gamma))))))^k));
end
i1 = 0;
i1 = ((0.5*(1-(sqrt((g*gamma)/(m+(g*gamma))))))^LM)*s;
s=0;
for k=0:LM-1
s=s+(nchoosek(2*k,k)*(1/((4*((mu^2)+1))^k)));
end
t=0;
for l=1:LM-1
for i=1:l
t=t+(((nchoosek(2*l,l))/((nchoosek(2*(l-i),(l-i)))*((4^i)*(2*(l-i)+1))))/(((mu^2)+1)^l))*((cos(atan(alpha)))^(2*(l-i)+1));
end
end
i2 = 0;
i2 = (1/4)-(beta*(0.5-(atan(alpha)/pi)))*s-((beta*((sin(atan(alpha)))/pi))*t);
p = (4*(1-(1/sqrt(M))))*i1 - (4*(1-(1/sqrt(M))))*i2;
ber = p;
the output should be one of the curves like this
but this is what i get
%

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

질문:

Sam
2014년 7월 2일

편집:

Sam
2014년 7월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by