Summation with upper limit itself as a variable
6 views (last 30 days)
Show older comments
i m trying to optimize the following function
z=-(r)*(L/M)*(1-(((L/M).^x(1))/((gamma(x(1)+1))*symsum(((L/M).^p)/(gamma(p+1)),p,0,x(1)))))+c*x(1);
with
syms p
r=2;
L=10;
M=2;
c=1;
and getting the following error
??? Error using ==> mupadmex
Error in MuPAD command: Illegal range [sum::sum]
can anybody help me how can i set the upper limit as variable in summation??
6 Comments
Walter Roberson
on 19 May 2013
The code you show never has "x" as a symbolic variable, so your upper bound is always numeric. I need to see the version of the code that has the error.
Answers (2)
Roger Stafford
on 20 May 2013
Edited: Roger Stafford
on 20 May 2013
In the expression
symsum((L/M)^p/gamma(p+1),p,0,n)
for p an integer ranging from 0 to n it is the sum of the first n+1 terms in the infinite power series expansion for the exponential function exp(L/M). It is extremely doubtful that there exists any known "closed form" for this finite summation in terms of a general n. In integral calculus, there are some integrals for which there are known closed forms (which one can usually find listed in integral tables) but many more for which none are known. In an analogous way there are finite summations for which there are known closed forms such as
symsum(p^2,p,1,n) = n*(n+1)*(2*n+1)/6
and many more for which none are known. As I say, it is very likely the summation you describe belongs to that latter category. One should therefore not blame Mupad for not finding it.
1 Comment
Walter Roberson
on 20 May 2013
Correct, but MuPAD would not return an error about invalid range for that case. MuPAD would create an unevaluted sum() expression (which might get converted to symsum() at the MATLAB level)
Amir
on 20 May 2013
2 Comments
Roger Stafford
on 20 May 2013
The issue, Amir, is that (presumably) no-one has yet found out how to express your sum as a compact general formula in terms of an unlimited variable x except by using the type of "symsum" or "sum" notation you already have here, and therefore our computers are also unable to do so. With your limit of 100 it would be possible to do the equivalent of listing all one hundred possibilities, but that is surely not what you are looking for.
Walter Roberson
on 20 May 2013
The error you reported earlier has to do with the bounds being invalid, but you have not yet shown us a code example in which the code using a variable as the upper bound.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!