1

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

1 Answers1

0

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

acl
  • 19,834
  • 3
  • 66
  • 91