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


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

Re: How to define a localized indexed object in Manipulate?

Started byBob Hanlon <hanlonr357@gmail.com>
First post2011-12-20 08:10 +0000
Last post2011-12-21 11:58 +0000
Articles 2 — 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: How to define a localized indexed object in Manipulate? Bob Hanlon <hanlonr357@gmail.com> - 2011-12-20 08:10 +0000
    Re: How to define a localized indexed object in Manipulate? "Nasser M. Abbasi" <nma@12000.org> - 2011-12-21 11:58 +0000

#7373 — Re: How to define a localized indexed object in Manipulate?

FromBob Hanlon <hanlonr357@gmail.com>
Date2011-12-20 08:10 +0000
SubjectRe: How to define a localized indexed object in Manipulate?
Message-ID<jcpftv$qim$1@smc.vnet.net>
I forgot that you wanted p localized. You can use Module to keep p out
of the global context.

Clear[p]

Module[{p},
 Manipulate[
  p@n = n;
  StringForm["p@`1` = `1`; Sum = `2`", n, Sum[p[k], {k, n}]],
  Button["Click to update p@n", n++],
  {{n, 0}, None}]]

?? p


Bob Hanlon


On Mon, Dec 19, 2011 at 8:34 AM, Bob Hanlon <hanlonr357@gmail.com> wrote:
> Clear[p]
>
> Manipulate[
>  p@n = n;
>  StringForm["p@`1` = `1`", n],
>  Button["Click to update p@n", n++],
>  {{n, 0}, None}]
>
> ?? p
>
>
> Bob Hanlon
>
> On Mon, Dec 19, 2011 at 7:16 AM, Nasser M. Abbasi <nma@12000.org> wrote:
>> On 12/18/2011 11:57 AM, DrMajorBob wrote:
>>> p@x is not an "indexed object", whatever that means.
>>>
>>
>> "Making Definitions for Indexed Objects"
>>
>> http://reference.wolfram.com/mathematica/tutorial/MakingDefinitionsForIndexedObjects.html
>>
>>> p is a function, and p@x is p at the argument x, or p[x].
>>>
>>
>> p[x] = whatever
>>
>> is an indexed object not a function. I use indexed objects all
>> the time. I just do not know how to use them inside Manipulate
>> as a Manipulate Control->None type.
>>
>> --Nasser
>>
>>> p@x also is not a variable, so it can't be treated as a variable in the
>>> second argument of Manipulate.
>>>
>>> Bobby
>>>
>>> On Sun, 18 Dec 2011 03:37:46 -0600, Nasser M. Abbasi<nma@12000.org>  wrote:
>>>
>>>>
>>>> Hello,
>>>>
>>>> Any one knows how to define and use an indexed object in Manipulate?
>>>>
>>>> Looking at the example below, p@x is an indexed object used by
>>>> Manipulate.
>>>>
>>>> --------------------------------
>>>> Manipulate[
>>>>     p@x=p@x+1;
>>>>     n;
>>>>     Row[{"p@x=",p@x}],
>>>>
>>>>     Button["click to update p@x",n++],
>>>>     {{n,0},None},
>>>>     TrackedSymbols:>{n},
>>>>
>>>>     Initialization:>
>>>>     {
>>>>       p@x=0
>>>>     }
>>>> ]
>>>> --------------------------------
>>>>
>>>> But in the above, I had to put p@x in the  Initialization section
>>>> because I did not know how to make a Manipulate Dynamic. This
>>>> makes p@x become global, and will not be localized when one makes
>>>> a new copy of the Manipulate snapshot, causing a problem.
>>>>
>>>> The obvious solution, which is to add
>>>>
>>>> {{p@x,0},None}
>>>>
>>>> to make p@x become a Manipulate own Dynamic, does not work for
>>>> indexed object. So, I could not do the following:
>>>>
>>>> --------------------------------
>>>> Manipulate[
>>>>     p@x=p@x+1;
>>>>     n;
>>>>     Row[{"p@x=",p@x}],
>>>>
>>>>     Button["click to update p@x",n++],
>>>>     {{n,0},None},
>>>>     {{p@x,0},None},    (* DOES NOT WORK, what is the synatx to use?*)
>>>>     TrackedSymbols:>{n}
>>>> ]
>>>> --------------------------------
>>>>
>>>> Any tick or hint how to do this will be great.
>>>>
>>>> Thank you,
>>>> --Nasser
>>>>

[toc] | [next] | [standalone]


#7384

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-12-21 11:58 +0000
Message-ID<jcshkq$2a7$1@smc.vnet.net>
In reply to#7373
On 12/20/2011 2:10 AM, Bob Hanlon wrote:
> I forgot that you wanted p localized. You can use Module to keep p out
> of the global context.
>
> Clear[p]
>
> Module[{p},
>   Manipulate[
>    p@n = n;
>    StringForm["p@`1` = `1`; Sum = `2`", n, Sum[p[k], {k, n}]],
>    Button["Click to update p@n", n++],
>    {{n, 0}, None}]]
>
> ?? p
>
>

Thanks Bob, But sorry I forgot to mention that this
is for a demonstration Manipulate type. Hence, one is
not allowed to have a Module outside Maniuplate. (One
of the rules for writing demonstration is that Manipulate
must be the first thing).

--Nasser


[toc] | [prev] | [standalone]


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


csiph-web