MathGroup Archive 2002

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

Search the Archive

RE: Trace a function

  • To: mathgroup at
  • Subject: [mg34990] RE: [mg34978] Trace a function
  • From: "David Park" <djmp at>
  • Date: Tue, 18 Jun 2002 02:48:31 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


With a little work you can duplicate the graphical calculator trace plot

Here are are a couple of routines and an example.


This routine extracts the plot points from a plot statement. You use it just
like you use a Plot statement.

GeneratePlotPoints[f_, iter_, opts___?OptionQ] :=
  Block[{g, pts, $DisplayFunction = Identity},
    g = First[Plot[f, iter, opts]];
    First[Cases[g, Line[pts_] -> pts, Infinity]]

This generates the points for a sample curve. The points are the ones that
Mathematica's adaptive plotting routine generated.

pts = GeneratePlotPoints[x^2, {x, 0, 1}];

We are going to generate an animation that will plot the line in black, a
selected point in Red, and label the coordinates of the point at a user
specified text position in the plot.

trace[npoint_, pts_, textposition_] :=
    Module[{x, y},
      {x, y} = pts[[npoint]];
            AbsolutePointSize[5], Red,
            Point[{x, y}],
            Text[SequenceForm["x = ", NumberForm[x, 3], "\ny = ",
                NumberForm[y, 3]], textposition, {-1, 0}]}],
        Frame -> True,
        FrameLabel -> {"x", "y"},
        ImageSize -> 500]];

You could look a a specific point by evaluating trace with the point index,
or better yet produce an animation.

Animate[trace[n, pts, Scaled[{0.1, 0.9}]], {n, 1, Length[gpoints], 1}]
SelectionMove[EvaluationNotebook[], All, GeneratedCell]

Use the up and down arrow keys to trace the point along the curve and see
the coordinate values. (Using the up and down arrow keys are often the best
method for viewing an animation.)

David Park
djmp at

> From: Declan O'Reilly [mailto:declan at]
To: mathgroup at
> Hi
>     Is there a way to trace along the plot of a function similar to the
> 'Trace' functionality on a graphing calculator.
> Thanks
> Declan O'Reilly

  • Prev by Date: RE: RE: Definitions of the functions
  • Next by Date: Re: Functionality and Reliability
  • Previous by thread: Trace a function
  • Next by thread: Re: RE: Trace a function