Off[General::spell1];

fun[x_] := Expand[(x-2)(x+1)(x+2)];

Tangent Movie

In this notebook you will use calculus and the Mathematica function Animate to produce the frames of a movie. 
Or use the function Manipulate to make an interactive demonstration.

Mathematica movies

It is easy to make simple Mathematica movies.  Here’s how.

The next cell gives the graph of the function  x ↦ 2x+3.

Plot[2x+3,{x,-4,4}
,PlotRange->{{-4,4},{-8,8}}]

Despite appearances it is a line with slope 2.  
Now imagine the family of lines  x↦m x+3 that is obtained as the parameter m varies.  
The following instruction produces continuously varying graphs, with slopes between ±3.

Animate[ 
Plot[ m*x+3
, {x,-4,4}
, PlotRange->{{-4,4},{-8,8}} 
]
 ,{m,-3,3} ]

The frames of a Mathematica  movie are shown within a Controller.  
While the movie is running you can adjust the way it works by using the controls that appear above the display area.
You can pause on any frame, or make it run faster/slower and reverse or loop forwards–backwards.

Exercise:  Modify the instruction below so that it produces parallel translates of the graph of the function x↦2x . Then produce a movie.  You should see a line moving horizontally across the graph.

Animate[Plot[2x,{x,-4,4}
, PlotRange->{{-4,4},{-8,8}}]
, {c,-3,3}]

Your Mathematica movie

You have been assigned your own polynomial fun[x].  Here it is:

fun[x]

And here is its graph:

Plot[fun[x],{x,-4,4},PlotRange->{{-4,4},{-20,20}}]

It is easy to get the derivative of fun:

fun'[x]

Plot[{fun[x],$$$},{x,-4,4},PlotRange->{{-4,4},{-20,20}}]

Animate[Plot[{fun[x],$$$}
,{x,-4,4}
,PlotRange->{{-4,4},{-20,20}}
]
, {a,-3,3}]

Power movies

You can see how easy it is to make a Mathematica movie.   If you successfully answered the last exercise, you could make a tangent movie for another function simplify by modifying the above code.  It would be even better to have a Mathematica command tangentMovie that takes any function you give it and produces a tangent movie for the function, in the same way that Plot takes any expression and produces its graph.  Unfortunately there is a limit to the number of built-in Mathematica commands, and tangentMovie is not one of them.

Remember though that Mathematica is a programming language.  What that means is that if a command that you would like to have is not immediately available then you can make you own.

tangentMovie[f_ ,{{xmin_,xmax_},{ymin_,ymax_}}]:= Animate[
 Plot[ {f[x],$$$}
	,{x,xmin,xmax}
	, PlotRange->{{xmin,xmax},{ymin,ymax}}
	]
	, {a,xmin,xmax}]

The code you replace $$$ with must explicitly involve the function f.  Also, remember that in Mathematica  the derivative of f is simply f'.

The expression you need must give the value at x of the tangent to f which passes through the point (a,f(a)).  
It is a straight line with slope f'(a).  Use a pencil and paper to work out its equation.

If you solved the exercise correctly, then the following command will produce the tangent movie for your function fun.

tangentMovie[fun,{{-4,4},{-20,20}}]

And the following command will produce the tangent movie for the function Exp.

tangentMovie[Exp,{{-3,3},{Exp[-3],Exp[3]}}]