complex equation with summation
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (2개)
Geoff Hayes
2014년 7월 2일
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?
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Gamma Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!