RE: Trace a function
- To: mathgroup at smc.vnet.net
- Subject: [mg34990] RE: [mg34978] Trace a function
- From: "David Park" <djmp at earthlink.net>
- Date: Tue, 18 Jun 2002 02:48:31 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Declan, With a little work you can duplicate the graphical calculator trace plot function. Here are are a couple of routines and an example. Needs["Graphics`Animation`"] Needs["Graphics`Colors`"] 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]]; Show[Graphics[ {Line[pts], AbsolutePointSize[5], Red, Point[{x, y}], Black, 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] FrontEndTokenExecute["OpenCloseGroup"] FrontEndTokenExecute["SelectionAnimate"] 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 earthlink.net http://home.earthlink.net/~djmp/ > From: Declan O'Reilly [mailto:declan at mcs.com] To: mathgroup at smc.vnet.net > > > 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 > >
- Follow-Ups:
- Re: RE: Trace a function
- From: Murray Eisenberg <murraye@attbi.com>
- Re: RE: Trace a function