complex equation with summation
3 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Geoff Hayes
on 2 Jul 2014
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 Comments
See Also
Categories
Find more on Gamma Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!