MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Locator question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79433] Re: Locator question
  • From: Albert <awnl at arcor.net>
  • Date: Thu, 26 Jul 2007 06:30:16 -0400 (EDT)
  • References: <f86r55$pc7$1@smc.vnet.net> <200707250930.FAA26363@smc.vnet.net> <f89pve$5jn$1@smc.vnet.net>

Hi,

> Attempt 1:
> 
>    trackPointOnPlot[f_, {a_, b_}, start_: {a, f[a]}] :=
>     DynamicModule[{p = start},
>      Column[{LocatorPane[Dynamic[p, (p = {First@#, f[First@#]}) &],
>         Plot[Sin[x], {x, a, b}]], Dynamic[p]}]]
> 
> then the locator appears initially to the left of the x-axis. So I ask 
> whether that syntax on the left for trackPointOnPlot is legitimate? That 
> is, can the default value for variable 'start' refer legitimately to the 
> value of a preceding argument?

Obviously Mathematica accepts the Syntax without complaining, but it 
does not do what you intended, you can check that with an additional 
Print[start]...

> What I'd REALLY like is a form such as the following -- which is illegal 
> Mathematica syntax!
> 
>    trackPointOnPlot[f_, {a_, b_}, {x0_,y0_}:{a,f[a]}] :=
>      DynamicModule[{p = {x0, y0}},
>         Column[{LocatorPane[Dynamic[p, (p = {First@#, f[First@#]}) &],
>          Plot[Sin[x], {x, a, b}]], Dynamic[p]}]]
> 
> How close can one get to that?

The question is, how important is it for you to get the behaviour with 
just one definition. Remember that you can solve your problem easily 
with an additionl definition for trackPointOnPlot:

trackPointOnPlot[f_,{a_,b_}]:=trackPointOnPlot[f,{a,b},{}]


The following is my attempt to solve your issue, it only uses one 
definition, but introduces some extra code...

trackPointOnPlot[f_, {a_, b_}, strt_: Automatic] :=
  Module[{start = strt /. Automatic -> {a, f[a]}},
    DynamicModule[{p = start},
     Column[{LocatorPane[Dynamic[p, (p = {First@#, f[First@#]}) &],
        Plot[f[x], {x, a, b}]], Dynamic[p]}]]
   ]

(not that I also replaced the Sin in the Plot which makes the outcome 
somewhat less confusing when f != Sin :-)

hth,

albert


  • Prev by Date: RE: Re: Re: Wolfram Workbench 1.1 now available
  • Next by Date: approximation
  • Previous by thread: Re: Re: Locator question
  • Next by thread: Re: Re: Locator question