MathGroup Archive 2007

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

Search the Archive

Re: Re: Locator question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg79452] Re: [mg79433] Re: Locator question
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Fri, 27 Jul 2007 05:48:07 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <f86r55$pc7$1@smc.vnet.net> <200707250930.FAA26363@smc.vnet.net> <f89pve$5jn$1@smc.vnet.net> <200707261030.GAA09683@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

Very nice!  An observation and a question:

1. Probably it would be more reasonable that the third, optional, 
argument be not an {x,y} point, but instead the x-coordinate of that 
point, since the point is supposed to be on the graph anyway. The 
modification for that is trivial:

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

2. Where/how did you discover the "trick" of using Automatic as a 
default value for an argument?  I don't recall seeing that before.

Albert wrote:
> ...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]}]]
>    ]

Of course, per your suggestion, a simpler way but now using only the 
x-coordinate as third, optional, argument is:

    trackPointOnPlot[f_, {a_, b_}, start_] :=
       DynamicModule[{p = {start, f[start]}},
          Column[{LocatorPane[Dynamic[p, (p = {First@#, f[First@#]}) &],
                  Plot[f[x], {x, a, b}]], Dynamic[p]}]]

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

-- 
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305


  • Prev by Date: Re: Re: Cyclic permutations
  • Next by Date: Re: Re: style question
  • Previous by thread: Re: Locator question
  • Next by thread: Re: Locator question