1
$\begingroup$

I have a manipulation problem that I can't find a solution online. Here is a simple example from my case.

constraint = RandomInteger[{1, 10}];
L1 = k RandomReal[{-10, 10}, {1, constraint}];
L2 = Table[{Subscript[b, i]}, {i, 1, constraint}];
y = Total[Flatten[L1.L2]]
With[{y = y},
  Manipulate[
    Plot[y, {k, 1, 10}], 
    {Subscript[b, 1], 0, 1}, 
    {Subscript[b, 2], 0, 1}, 
    {Subscript[b, 3], 0, 1}, 
    {Subscript[b, 4], 0, 1}, 
    {Subscript[b, 5], 0, 1}, 
    {Subscript[b, 6], 0, 1}, 
    {Subscript[b, 7], 0, 1}, 
    {Subscript[b, 8], 0, 1}, 
    {Subscript[b, 9], 0, 1}, 
    {Subscript[b,,10], 0, 1}]]

My question is that is there a way to auto generate the parameters in Manipulate according to my constraint?

$\endgroup$
0
$\begingroup$

I feel like there is a duplicate, but I was not able to find this. This one is related e.g: 1199

All you need is:

With[{y = y}, 
 Manipulate[
  Plot[y, {k, 1, 10}],
  Evaluate @ Array[{Subscript[b, #], 0, 1} &, constraint, 1, Sequence]
  ]]

You sould be able to figure it out with documentation. Evaluate is for the same purpose as your With.

p.s. It is good habit to not use Subscripts.

$\endgroup$
1
  • $\begingroup$ @user11726 No problem, good luck. :) p.s. there is no need to accept immediately, you can always upvote (if you find answer useful) and accept later, maybe even different answer. Please, take a tour $\endgroup$ – Kuba Feb 10 '15 at 10:10

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.