Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am required to write a function that takes a function as a parameter.

moveTwoPoints[function_, {sliderMin_, sliderMax_}] := 
  {sliderValue = sliderMin,
  f[x_] := function;
(*Display slider *)
Slider[Dynamic[sliderValue], {sliderMin, sliderMax}],
(*Display updating slider value *)
(*Display the graph with points moving*)
  Plot[f[x], {x, sliderMin, sliderMax}], 
   {Red, PointSize[Large], Point[{sliderValue, f[sliderValue]}], 
    Green, PointSize[Large], Point[{0, f[sliderValue]}]

The problem I am running into is the fact that when I try f[sliderValue] is won't return a point just the value of function. Is there a way I can manipulate this function?

share|improve this question
up vote 1 down vote accepted

Do you mean this?

f[func_, {Min_, Max_}] :=Manipulate[
  Column[{a,Plot[func[x], {x, Min, Max}, 
      Epilog -> {Red, PointSize[Large], Point[{a, func[a]}], 
      Green, PointSize[Large], Point[{0, func[a]}]}]}, 
  Alignment -> Center], {a, Min, Max}]
f[Sin[#] &, {0, 2 Pi}]
share|improve this answer
Yeah that is what I meant. The requirements for the problem are to create a slider and show a point along the y axis that mirrors a red point that follows the function. Your solution is great, I don't know if it would earn me full credit tho. How did you function change the values of the y coordinate using func[a]? I feel like my solution should have worked with that. @Chenminqi – Peter Kaminski Mar 13 '14 at 16:00
Is there a way to do that without using manipulate? @chenminqi – Peter Kaminski Mar 13 '14 at 16:02
Manipulate is a good function for dynamic demo. – Apple Mar 13 '14 at 16:02
Okay, manipulate makes sense but after re-reading the problem it states that I must use Dynamic Module. I will try to work with that. @chenminqi – Peter Kaminski Mar 13 '14 at 16:03
Of course without using manipulate.But I need go to sleep ,so...tomorrow. – Apple Mar 13 '14 at 16:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.