Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #13918 > unrolled thread

Re: Manipulate and Initialization

Started byBob Hanlon <hanlonr357@gmail.com>
First post2013-03-24 08:16 +0000
Last post2013-04-03 07:22 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Manipulate and Initialization Bob Hanlon <hanlonr357@gmail.com> - 2013-03-24 08:16 +0000
    Re: Manipulate and Initialization debguy <johnandsara2@cox.net> - 2013-04-02 07:25 +0000
    Re: Manipulate and Initialization debguy <johnandsara2@cox.net> - 2013-04-03 07:22 +0000

#13918 — Re: Manipulate and Initialization

FromBob Hanlon <hanlonr357@gmail.com>
Date2013-03-24 08:16 +0000
SubjectRe: Manipulate and Initialization
Message-ID<kimcog$pr5$1@smc.vnet.net>
Use Dynamic

nn = 23;
Manipulate[n,
 {n, 1, Dynamic[nn], 1, Appearance -> "Labeled"},
 Initialization :>
  (nn = RandomInteger[{5, 15}]; Print[nn])]


Bob Hanlon


On Sat, Mar 23, 2013 at 3:24 AM, Fred Simons <f.h.simons@tue.nl> wrote:
> I want to create a rather complicated Manipulate, in which I do not know
> the limits for the parameter beforehand; they depend on the result of an
> initialization. Here is a highly simplfied example:
>
> Clear[nn];
> Manipulate[n, {n,1,nn,1},
> Initialization:>(nn=RandomInteger[{5,15}];Print[nn])]
>
> This works fine. The slider can be used in the range from 1 to the
> printed value.
>
> However, when nn already has a value, the behaviour is different. When
> we execute
>
> nn=23;
> Manipulate[n, {n,1,nn,1},
> Initialization:>(nn=RandomInteger[{5,15}];Print[nn])]
>
> a value between 5 and 15 for nn is printed, but that value is not used
> in the result; the slider now runs from 1 to 23.
>
> So, whether nn has a value or not, just before the box structure is
> printed, the frontend asks the kernel to evaluate the initialization.
> But the returned value of nn is used in Manipulate only when nn did not
> have a value before. That embarasses me. Any explanation is highly
> apprectiated.
>
> Fred Simons
> Eindhoven University of Technology
>

[toc] | [next] | [standalone]


#14006

Fromdebguy <johnandsara2@cox.net>
Date2013-04-02 07:25 +0000
Message-ID<kje15f$gvk$1@smc.vnet.net>
In reply to#13918
I think this is more what you asked.

Clear[nn];
Manipulate[n, {n,1,nn,1},
Initialization:>(nn=RandomInteger[{5,15}];Print[nn])]

"This works fine. The slider can be used in the range from 1 to the
printed value."

Ok.  Isolate the name of nn.

nn=23;
Module[{nn},
Manipulate[n, {n,1,nn,1},
Initialization:>(nn=RandomInteger[{5,15}];Print[nn])]
]

or use a different name than Global`nn which i think is clashing

Manipulate[n, {n,1,a`nn,1},
Initialization:>(a`nn=RandomInteger[{5,15}];Print[a`nn])]

(btw module actually uses $123nn as the name, and using Global`nn
would be 23)

Dynamic likely works because (xxx) but you may not want dynamic update
it might be too slow for your application.  So you might need the
above.

[toc] | [prev] | [next] | [standalone]


#14026

Fromdebguy <johnandsara2@cox.net>
Date2013-04-03 07:22 +0000
Message-ID<kjglbc$p44$1@smc.vnet.net>
In reply to#13918
I think this is more what you asked.

Clear[nn];
Manipulate[n, {n,1,nn,1},
Initialization:>(nn=RandomInteger[{5,15}];Print[nn])]

"This works fine. The slider can be used in the range from 1 to the
printed value."

Ok.  Isolate the name of nn.

nn=23;
Module[{nn},
Manipulate[n, {n,1,nn,1},
Initialization:>(nn=RandomInteger[{5,15}];Print[nn])]
]

or use a different name than Global`nn which i think is clashing

Manipulate[n, {n,1,a`nn,1},
Initialization:>(a`nn=RandomInteger[{5,15}];Print[a`nn])]

(btw module actually uses $123nn as the name, and using Global`nn
would be 23)

Dynamic likely works because (xxx) but you may not want dynamic update
it might be too slow for your application.  So you might need the
above.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web