1

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?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
user11726
  • 105
  • 4

1 Answers1

0

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.

Kuba
  • 136,707
  • 13
  • 279
  • 740
  • @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 – Kuba Feb 10 '15 at 10:10