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!