# Working with functions

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

moveTwoPoints[function_, {sliderMin_, sliderMax_}] :=
DynamicModule[
{sliderValue = sliderMin,
plot},
f[x_] := function;
Column[
{
(*Display slider *)
Slider[Dynamic[sliderValue], {sliderMin, sliderMax}],
(*Display updating slider value *)
Dynamic[sliderValue],
(*Display the graph with points moving*)
Dynamic[
Show[
Plot[f[x], {x, sliderMin, sliderMax}],
Graphics[
{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?

-

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}]

-
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 –  indieDev Mar 13 at 16:00
Is there a way to do that without using manipulate? @chenminqi –  indieDev Mar 13 at 16:02
Manipulate is a good function for dynamic demo. –  Chenminqi Mar 13 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 –  indieDev Mar 13 at 16:03
Of course without using manipulate.But I need go to sleep ,so...tomorrow. –  Chenminqi Mar 13 at 16:03