Message Boards Message Boards

How can I draw an arrow from a function of x to the y axis?

Posted 10 years ago

Given a curve like this with a slider for x:

Manipulate[   
 f[x_] := .5*2 x^2;    
 Plot[{f[x]}, {x, 0, 1}],    
 {{x, .5, "X"}, 0, 1, .01}    
 ] 

How can I draw a horizontal arrow from the curve at the current value of x to the y axis with the y value text on the arrow.
Thank you. Joe Rimback

POSTED BY: Joe Rimback
2 Replies

Note that your x in your plot needs to be different from your x in your Manipulate slider. So calling the latter xx instead, here is a possibility for you:

Manipulate[
 Plot[{f[x]}, {x, 0, 1}, 
  Epilog -> {Text[f[xx], {xx/2, f[xx]}, {0, -1}], 
    Arrow[{{xx, f[xx]}, {0, f[xx]}}]}],
 {{xx, .5, "X"}, 0, 1, .01},
 Initialization :> {f[x_] := .5*2 x^2}
 ]

Also note that the way you included your definition of f in your example code is very problematic and leads to a Manipulate that is in an infinite execution loop. Define f in an Initialization option instead as above.

POSTED BY: David Reiss
Posted 10 years ago

Thanks David - I'm learning how to learn. Like your website. I will send you a copy of the annuity app in its current state next week - so you can see how you helped.

POSTED BY: Joe Rimback
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract