MATLAB: Summing An infinite Series

beginnerfunctionsMATLABseries

Hi !
I'm a little new to MATLAB but am trying to use it to check the values for part of an infinite sum I have to implement in Python.
This is the sum in question.
And this is my code:
function the_sum = p_sum(l,m,n,alpha,beta,gamma)
syms p;
the_sum = syssum(factorial(l+m+n+p+2)/(factorial(l+1+p)*(l+m+2+p)) * (alpha/(alpha + beta + gamma))^p,p,0,Inf);
end
But when I run it I get an error ! I imagine I'm doing something rather simple that is wrong and would be so grateful if someone could point me in the right direction !

Best Answer

I might start by using the correct function. In MATLAB, that is symsum, not syssum. :) These dumb computers, they refuse to read our minds.
You don't tell us what error you got. It is almost always best to show the ENTIRE error message, as that will usually tell what the problem is immediately. Here, it should probably have said something about syssum not existing. But that is only a wild guess on my part, since you also don't show enough to really test what you are doing.
As for doing the computation itself in numerical form, you could probably play around with Stirlings approximation for those factorials. However, symsum seems to handle it well enough.
l = 2;
m = 1;
n = 2;
alp = .3;
bet = .7;
gam = .4;
symsum(factorial(l+m+n+p+2)/(factorial(l+1+p)*(l+m+2+p)) * (alp/(alp + bet + gam))^p,p,0,Inf)
ans =
3757404/14641
Be careful in defining variables named alpha, beta, and gamma, as they are already the names of useful functions in MATLAB. That will cause problems later on.
I would also strongly suggest that you NOT use a variable name of lower case L, thus l. As you can see, it is quite easily mistaken for the number 1, depending on the font used. One day, you will trip over a bug in your code, and not have a clue what is wrong, because you mistyped the variable name as a 1, or the opposite. As such, I STRONGLY recommend you avoid use of the variable names: lower case L (l), upper case i (I), or either case o or O.