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 Do to produce the frames of a movie.

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 seven of them.

Do[Print[Plot[m x+3,{x,-4,4},PlotRange->{{-4,4},{-8,8}}]],{m,-3,3,1}]

The seven graphs are the frames of a Mathematica  movie that you can view by double-clicking on one of the frames.  While the movie is running you can control the way it works by using the dials that appear in the lower left corner of the window.  Pressing a number from 1 to 9 will also change the speed.

Exercise:  Modify the instruction below so that it produces seven parallel translates  of the graph of the function x -> 2x.  Then run the seven frames as a movie.  You should see a line moving horizontally across the graph.

Do[Print[Plot[2 x,{x,-4,4},PlotRange->{{-4,4},{-8,8}}]],{c,-3,3,1}]

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

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

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_}}]:=Do[Print[Plot[{f[x],$$$},{x,xmin,xmax},PlotRange->{{xmin,xmax},{ymin,ymax}}]],{a,xmin,xmax,1}]

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