0

Is there someone who can explain why this manipulate does not work

v = {a, b, c}; s = sn;
amapp[v_, s_] := Module[{vv = v, ss = s}, d = Total[vv]/ss;
   q = N[vv/d];
  qq = \[LeftFloor]q\[RightFloor];
  res = q - qq;(*reste*)
  raa = ss - Total[qq];(*reste à attribuer*)
  raa1 = Table[1, {i, Length[vv]}];
  res1 = Table[
    If[MemberQ[Ordering[res, raa, #1 > #2 &], i], qq[[i]] + raa1[[i]],
      qq[[i]]], {i, Length[qq]}]]
Manipulate[
 amapp[v, s], {a, 1, 1000}, {b, 1, 1000}, {c, 1, 1000}, {sn, 1, 1000}]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
cyrille.piatecki
  • 4,582
  • 13
  • 26

1 Answers1

1

You can see the problem with:

Manipulate[{v, s}, {a, 1, 1000}, {b, 1,1000}, {c, 1, 1000}, {sn, 1, 1000}]

a,b,c remain unevaluated with your v and s defined outside your Manipulate. Why? Because the a,b,c in your Manipulate are locally scoped. Can see e.g. w/ Manipulate[{Hold[FullForm[a]], FullForm[v]}, {a, 1, 1000}]. Sometimes using Hold[FullForm[.]] can help you figure out the actual variable names at play are.

Can resolve e.g. (as Kuba comments) with:

Manipulate[amapp[{a, b, c}, sn], {a, 1, 1000}, {b, 1, 1000}, {c, 1, 1000}, {sn, 1, 1000}]

Or if you insist on defining a v and s, do so within the Manipulate:

Manipulate[v = {a, b, c}; s = sn; 
 amapp[v, s], {a, 1, 1000}, {b, 1, 1000}, {c, 1, 1000}, {sn, 1, 1000}]
  • Sometimes I feel so stupid. Thanks, Both of you. But I must underline that what, at the end, I want is to have the length of v variable. Do you know how to do this ? – cyrille.piatecki Aug 24 '17 at 09:25
  • Let me see if I understand. You want to manipulate the length and content of $v$? i.e. have a slider for size of your vector $v$ and a separate slider for each of those $v_1, \ldots , v_n$? – John Joseph M. Carrasco Aug 24 '17 at 09:43