Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Say I had a function like the following:

f[n_] := Sum[a + Subscript[b, k], {k, 0, n}]

Such that f[5] == 6 a + Subscript[b, 0] + Subscript[b, 1] + Subscript[b, 2] + Subscript[b, 3] + Subscript[b, 4] + Subscript[b, 5]

How would I go about minimizing f with respect to both a and all of the subscripted bs? How would I go about minimizing f[5] without manually supplying {a, Subscript[b, 0], Subscript[b, 1], Subscript[b, 2], Subscript[b, 3], Subscript[b, 4], Subscript[b, 5]} as the vars param?

I'm asking about a specific simplified case here, but hopefully answers will be applicable in the general case and to other functions that take a vars param other than Minimize[]

share|improve this question
did you look at this, this or any of the other similar questions around this site? – acl Jul 18 '14 at 16:55
up vote 0 down vote accepted

While this has been answered many times, let me answer it once more:

varnum = 10;
vars = Symbol["a" <> ToString[#]] & /@ Range[varnum];
of = Total[-vars^2 + vars^4];
Minimize[of, vars]

enter image description here

share|improve this answer
It would be more straightforward to define vars by vars = Array[a, varnum] – Bob Hanlon Jul 18 '14 at 17:47
@BobHanlon Perhaps, but I wanted them to be symbols – acl Jul 18 '14 at 17:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.