MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
Asked by Amir on 18 May 2013

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??

*No products are associated with this question.*

Answer by Roger Stafford on 20 May 2013

Edited by 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.

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)

Answer by Amir on 20 May 2013

i m not getting what is the issue? if i use the same expression without symsum(..), i'm being returned with the optimized values of function 'z' and decision variable 'x', which shows that code is working properly but with the induction of summation with upper bound as decision variable, it generates the error! is there any other way to induce the following summation here???

"∑ p=0 to x {(L/M)^p/p!}"

where xϵ{1,100}

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.

## 6 Comments

Direct link to this comment:http://mathworks.com/matlabcentral/answers/76236#comment_149636

You have not shown how you define x ?

Direct link to this comment:http://mathworks.com/matlabcentral/answers/76236#comment_149664

it is basically a part of algo where we want to find the best value of function and x(1). range of x(1) is defined within (1,100)

Direct link to this comment:http://mathworks.com/matlabcentral/answers/76236#comment_149667

if i give some numeric value instead of x(1), then it runs. according to my observation it takes numeric value in this format. is there anyother way to define summation with upper limit as free variable??

Direct link to this comment:http://mathworks.com/matlabcentral/answers/76236#comment_149698

Please show the statement you used to initialize x and to set the value of x(1)

Direct link to this comment:http://mathworks.com/matlabcentral/answers/76236#comment_149723

well! em using the algo available at web

http://www.mathworks.com/matlabcentral/fileexchange/29693-firefly-algorithm/content/fa_ndim.m

and trying to implement it for my objective function.

whole format is as follows;

Direct link to this comment:http://mathworks.com/matlabcentral/answers/76236#comment_149778

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.