# How would one minimize with respect to an unknown number of variables?

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[]

-
did you look at this, this or any of the other similar questions around this site? – acl Jul 18 '14 at 16:55

## 1 Answer

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]


-
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