Tracing a point on a graph and displaying the y value - Mathematica

In summary, to display the changing y value for the x value being shown on the slider bar in Mathematica 8, you can use the Epilog option and add a Text object with the desired format and coordinates. Keep exploring and experimenting with Mathematica, it is a powerful tool for scientific computing.
  • #1
chris_0101
65
0
Hey,

I am using Mathematica 8 and I finally figured out how to drag a point along a graph using a slider bar, which increases or decreases the x value. Now, I am stuck on how to display the y value for the changing x value on the screen.

My code is below:
parabola = Plot[x^2, {x, -4, 4}, Ticks -> False]

Manipulate [Show[parabola, Graphics [{Red, Disk [ {x, x^2}, 0.05]}],
PlotRange -> {{-4, 4}, {-4, 4}},
AspectRatio -> Automatic], {x, -4, 4}]

An image of my code
plot trace.JPG


Any help is appreciated,

Thanks
 
Physics news on Phys.org
  • #2
!



It looks like you are on the right track with your code. In order to display the changing y value on the screen, you can use the Epilog option in your Manipulate function. This allows you to add additional graphics or text to your plot. In your case, you can add a Text object that displays the y value for the current x value being shown by the slider bar. Here is an example of how you can modify your code to achieve this:

parabola = Plot[x^2, {x, -4, 4}, Ticks -> False]

Manipulate[
Show[parabola, Graphics[{Red, Disk[{x, x^2}, 0.05]}],
PlotRange -> {{-4, 4}, {-4, 4}}, AspectRatio -> Automatic,
Epilog -> {Text["y = " <> ToString[x^2], {3, 3}]}],
{x, -4, 4}]

This will display the y value for the current x value at the coordinates (3,3) on the plot. You can adjust the position and formatting of the Text object as needed. I hope this helps. Keep exploring and experimenting with Mathematica, it is a powerful tool for scientific computing.
 

FAQ: Tracing a point on a graph and displaying the y value - Mathematica

How do I trace a point on a graph in Mathematica?

To trace a point on a graph in Mathematica, you can use the "Locator" tool in the graph menu. Simply click on the "Locator" button and then click on the point you want to trace. The coordinates of the point will be displayed in a tooltip.

Can I display the y value of a traced point on a graph in Mathematica?

Yes, you can display the y value of a traced point by using the "Dynamic" function. Simply wrap the y coordinate of the point in the "Dynamic" function and it will be continuously updated as you move the traced point.

How can I change the style of the traced point on a graph in Mathematica?

You can change the style of the traced point by using the "LocatorPane" function. This allows you to customize the appearance of the locator, such as changing its color or size.

Is there a way to trace multiple points on a graph in Mathematica?

Yes, you can trace multiple points on a graph by using the "LocatorPane" function and setting the "Appearance" option to "None". This will hide the default locator and allow you to create multiple locators by clicking on different points on the graph.

How do I clear the traced points on a graph in Mathematica?

To clear the traced points on a graph, you can use the "Clear" function. Simply click on the "Clear" button in the graph menu or use the keyboard shortcut "Ctrl+L". This will remove all traced points from the graph.

Similar threads

Replies
1
Views
916
Replies
4
Views
2K
Replies
1
Views
1K
Replies
1
Views
806
Replies
1
Views
2K
Replies
1
Views
1K
Replies
1
Views
3K
Replies
1
Views
6K
Replies
1
Views
2K
Back
Top