Re: Re: Locator question
- To: mathgroup at smc.vnet.net
- Subject: [mg79404] Re: [mg79382] Re: Locator question
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Thu, 26 Jul 2007 05:27:05 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <f86r55$pc7$1@smc.vnet.net> <200707250930.FAA26363@smc.vnet.net>
- Reply-to: murray at math.umass.edu
I'd like to define a function that would do that, taking as argument the
function name, the interval on which to plot, and an optional point at
which to place the locator.
Here are two attempts, each with unpleasant consequences...
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]}]]
With a third argument supplied, this works OK, e.g.:
trackPointOnPlot[Sin, {0, 10}, {Pi, Sin[Pi]}]
However, if I evaluate, say,
trackPointOnPlot[Sin,{0,10}]
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?
Attempt 2: This uses what to me would be a more natural syntax if one is
going to supply the third argument:
trackPointOnPlot[f_, {a_, b_}, {x0_: 0, y0_: 0}] :=
DynamicModule[{p = {x0, y0}},
Column[{LocatorPane[Dynamic[p, (p = {First@#, f[First@#]}) &],
Plot[Sin[x], {x, a, b}]], Dynamic[p]}]]
Again this works OK with a third argument, e.g,
trackPointOnPlot[Sin, {0, 10}, {Pi, Sin[Pi]}].
However, to get it to work without explicitly supplying x- and y-
coordinates for a third argument but have it, instead, fall back to a
default, one must use the form:
trackPointOnPlot[Sin, {0, 10}, {}]
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?
Albert wrote:
>
> LocatorPane[Dynamic[pt],
> Plot[Sin[x], {x, 0, 10},
> Epilog -> {PointSize[Large],
> Point[Dynamic[{First[pt], Sin[First[pt]]}]]}], Appearance -> None]
--
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
- References:
- Re: Locator question
- From: Albert <awnl@arcor.net>
- Re: Locator question