1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ did you look at this, this or any of the other similar questions around this site? $\endgroup$ – acl Jul 18 '14 at 16:55
0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ It would be more straightforward to define vars by vars = Array[a, varnum] $\endgroup$ – Bob Hanlon Jul 18 '14 at 17:47
  • $\begingroup$ @BobHanlon Perhaps, but I wanted them to be symbols $\endgroup$ – acl Jul 18 '14 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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