Animate a point on a function?

Hi,

The code below don’t work!

f[x_] := x^2 + 2 x - 3
p = {{a, f[a]}}
Animate[ Plot[f[x], {x, -2, 4}, Epilog -> Point[p]], {a, -2, 4}]

But, If I replace the variable p with is evaluation, the code is OK.

Animate[Plot[f[x], {x, -2, 4}, Epilog -> Point[{{a, -3 + 2 a + a^2}}]], {a, -2, 4}]

I want to use the variable in my document. How can I do it?

Thank you.

Marcel Pelletier

f[x_] := x^2 + 2 x - 3
p[a_] := {{a, f[a]}}
Animate[Plot[f, {x, -2, 4}, Epilog → Point[p[a]]], {a, -2, 4}]

Anima.gif

Hi Valeriu.

Thank you for your help.
This will ameliorate my document.

Marcel Pelletier

You are welcome!

f[x_] := 2 x^3 + 2 x - 3
p[a_] := {{a, f[a]}}
t[x_, a_] := f[a] + (x - a) f’[a]
Animate[Plot[f, {x, -2, 4}, PlotRange → {{-2, 4}, {-24, 128}},
Epilog → {PointSize[Medium], Point[p[a]], Red,
InfiniteLine[{p[a][[1]], {0, t[0, a]}}]}], {a, -2, 4},
AnimationDirection → ForwardBackward]

Hi Valeriu,
Thank you for this new response!
I have create animations for my course.. Your help are welcome.
Marcel Pelletier

Hi, Marcel, I posted this new code for the tangent line as a suggestion for you to post other pieces of code that you are using in the course. They may be useful for others in the Wolfram Community and the Community may suggest new solutions and useful pieces of code. Sure, it’s your decision…