Manipulate Tutorial

The Manipulate command introduced in Mathematica 6 is revolutionary and has tremendous potential for mathematical investigation, instruction, and development/delivery of interactive curriculum. The freely available Mathematica Player software allows anyone to interact with dynamic graphics created with Manipulate. There are over 2000 Demonstrations at demonstrations.wolfram.com which are all built using the Manipulate command and are ready for immediate use and investigation (source code for all demonstrations is available).

This workshop assumes some familiarity with Mathematica commands but does not assume previous knowledge of Manipulate. Several dynamic visualizations are built step-by-step and  introduce manipulate controls and techniques along the way. Each section begins with a manipulate object that will be consturcted in the section.

Section 1. Exponential and logarithmic functions
Section 2. Slope and intercept of a line
Section 3. Distance between two points
Section 4. Intercept of tangent line
Section 5. Visualizing the slope of a line
Section 6. Derivatives of trigonometric functions
Further examples

Section 1. Exponential and logarithmic functions

Manipulate controls used in this example

SliderBar
		• Initial value specified
		• Increment value specified
		• Numeric value shown with Appearance->"Labeled" option
	Checkbox
		• Implementation of reset functionality for a manipulate object

Step by step process for building the manipulate

Start with a straightforward manipulate demonstrating the relationship between the exponential function f(x)=(b^x) and its inverse (f^(-1))(x)=(Subscript[log, b])(x). The process begins with the creation of a static picture which is then made interactive using Mathematica's Manipulate command.

Plot[{(2^x),Log[2,x],x},{x,-5,5}]

Modify the basic picture by plotting the exponential function using a thick red curve, the logarithmic function with a thick blue curve, and y=x with a dashed gray line. Additionally, set the vertical scale to -5≤y≤5,  use the AspectRatio option to ensure the horizontal and vertical scales are the same, and set the font size to 16 points with the BaseStyle option.

• Change the color and style used to plot the functions with PlotStyle->{{Thick, Red},{Thick, Blue},{Dashed, Gray}}.
• Set the vertical scale to [-5,5] with PlotRange->5. This short version of PlotRange is equivalent to PlotRange->{-5,5}.
• Set the scales on the two axis to be the same with AspectRatio->Automatic.
• Increase the font size using BaseStyle.

Plot[{(2^x),Log[2,x],x},{x,-5,5},PlotStyle->{{Thick,Red},{Thick,Blue},{Dashed,Gray}},PlotRange->5,AspectRatio->Automatic,BaseStyle->16]

Wrap Manipulate around the Plot command and replace the base of 2 with the parameter b to make the graph interactive. Let b range from 0.1 to 10.

The simplest syntax for a manipulate slider control is {name,min,max}.

Manipulate[
Plot[{(b^x),Log[b,x],x},{x,-5,5},PlotStyle->{{Thick,Red},{Thick,Blue},{Dashed,Gray}},PlotRange->5,AspectRatio->Automatic],{b,0.1,10}]

Specify e as the initial value for the b control, change the default increment size to 0.1, and label the scrollbar with the corresponding numeric value using the Appearance->"Labeled" option. The syntax for this slider control is {{name,start},min,max,increment,options}.

Manipulate[
Plot[{(b^x),Log[b,x],x},{x,-5,5},PlotStyle->{{Thick,Red},{Thick,Blue},{Dashed,Gray}},PlotRange->5,AspectRatio->Automatic],{{b,E},0.1,10,0.1,Appearance->"Labeled"}]

Every manipulate object can be set to the initial parameter values by selecting Initial Settings from the manipulate menu accessible by clicking on the ⊕ symbol in the upper right corner of the manipulate panel. There are many instances where it is desirable to reset a subset of the manipulate controls to their default settings rather than returning all parameters to their initial values. This reset functionality can be implemented with a checkbox control and a single If statement inserted at the beginning of the manipulate body as shown below. If the reset checkbox is selected (set to True), the true clause of the If statement is evaluated — note that one of the assignments made in the true clause is to set the reset checkbox parameter to False with the effect being that the checkmark in the reset checkbox immediately disappears.

Add a reset checkbox control and an If statement at the beginning of the manipulate body to provide reset functionality for  manipulate controls.

Manipulate[
If[reset,{b,reset}={E,False}];
Plot[{(b^x),Log[b,x],x},{x,-5,5},PlotStyle->{{Thick,Red},{Thick,Blue},{Dashed,Gray}},PlotRange->5,AspectRatio->Automatic],
{{b,E},0.1,10,0.1,Appearance->"Labeled"},
{{reset,False},{False,True}}]

If the parameter b is equal to 1 the plot area turns pink and an error message will be reported since a base of 1 in the logarithm function is problematic to say the least — try it. (If you cannot set b to 1 with the scrollbar control, then click on the tiny + icon at the right edge of the scrollbar, enter 1 in the input field, and press ⇥.) We add two If statements to remedy this potential problem.

Manipulate[
If[reset,{b,reset}={E,False}];
Plot[{If[b≠1,(b^x)],If[b≠1,Log[b,x]],x},{x,-5,5},PlotStyle->{{Thick,Red},{Thick,Blue},{Dashed,Gray}},PlotRange->5,AspectRatio->Automatic],
{{b,E},0.1,10,0.1,Appearance->"Labeled"},
{{reset,False},{False,True}}]

Section 2. Slope and intercept of a line

Manipulate controls used in this example

SliderBar
		• Initial value specified
		• Alternate text label specification
		• Increment value specified
		• Numeric value shown with Appearance->"Labeled" option
		• Size modified with ImageSize->Small option
		• Enabled & disabled with Enabled option
	Checkbox
		• Alternate text label specification
		• Enabled & disabled with Enabled option
	Delimiter and arbitrary formatted text

Step by step process for building the manipulate

In this example we use Manipulate to vary the two parameters m and b in the linear function f(x)=m x+b to visualize how the parameter values affect the plot of the function. Begin by creating a static picture showing the plot of some linear function.

Plot[2x-4,{x,-10,10}]

Wrap Manipulate[ ] around the Plot command while replacing the numeric values in the function with the parameters m and b with a range for each new parameter.

The simplest syntax for a manipulate slider control is {name,min,max}.

Manipulate[ 
Plot[m x+b,{x,-10,10}],
{m,-5,5},
{b,-10,10}]

That was easy, unfortunately the behavior of the interactive graph is a bit surprising since the y–scale is adjusted automatically by Mathematica as the parameter values change and it impossible to observe how changes in m affect the line. This sort of thing happens regularly when graphs become dynamic. Specify the PlotRange option value explicitly to remedy the problem:

Manipulate[
 Plot[m x+b,{x,-10,10},PlotRange->10],
{m,-5,5},
{b,-10,10}]

We now adjust visual features of the graph using options of the Plot command.

• Plot the line itself with bright red color using PlotStyle->{Thick,Red}.
• Set the scales on the two axis to be the same with AspectRatio->Automatic and guarantee that the two scales always intersect at (0,0) with the AxesOrigin->{0,0} option.
• Add light gray grid lines using GridLines and GridLinesStyle.
• Increase the font size of text using BaseStyle.

Manipulate[
 Plot[m x+b,{x,-10,10},PlotRange->10,
PlotStyle->{Thick,Red},
AspectRatio->Automatic,AxesOrigin->{0,0},
GridLines->{Range[-10,10],Range[-10,10]},GridLinesStyle->GrayLevel[0.9],
BaseStyle->14],
{m,-5,5},
{b,-10,10}]

The initial values for m and b are less than ideal and the control labels are useful only if the form f(x)=m x+b is familiar to the user. To address these issues we make the following changes to the scrollbar controls:

• Specify initial values for each control and give more descriptive labels for each control.
• Change the default increment size to 0.1 for the slope control and 0.1 for the intercept control. 
• Label each scrollbar with the corresponding numeric value.

The complete syntax for a slider control is {{name,start,"label"},min,max,increment,options}.

Manipulate[
 Plot[m x+b,{x,-10,10},PlotRange->10,
PlotStyle->{Thick,Red},
AspectRatio->Automatic,AxesOrigin->{0,0},
GridLines->{Range[-10,10],Range[-10,10]},GridLinesStyle->GrayLevel[0.9],
BaseStyle->14],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled"},
{{b,2,"y–intercept"},-10,10,0.1,Appearance->"Labeled"}]

The Manipulate command usually locates the controls at the top of the manipulate panel, if some other position is desired the location of the controls should be specified with the ControlPlacement option. If the ControlPlacement option is given inside of a parameter's list braces it will apply only to the individual control, however, if the ControlPlacement option is given after the parameters, then it will be applied to all of the controls. In the following example the scrollbar controls will be moved to the left side of the panel and their size will be decreased with an ImageSize option.

• Add ControlPlacment->Left at the end of the parameter controls so that it is applied to both controls (and all subsequent controls that will be added in this example.)
• Add the options ImageSize->Small to the scrollbar controls.

Manipulate[
  Plot[m x+b,{x,-10,10},PlotRange->10,
PlotStyle->{Thick,Red},
AspectRatio->Automatic,AxesOrigin->{0,0},
GridLines->{Range[-10,10],Range[-10,10]},GridLinesStyle->GrayLevel[0.9],
BaseStyle->14],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"y–intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
ControlPlacement->Left]

It would be nice to toggle the gridlines off and on with a single mouse click and reset the slope and intercept controls to their default values with a single mouse click too. Both of these tasks can be accomplished with the addition of two CheckBox controls to the list of manipulate parameters along with two If statements in the body of the manipulate. The reset functionality will be added first followed by the gridline toggle feature.

The manipulate reset functionality is handled by a single If statement at the beginning of the first argument whose true clause is executed the instant the reset checkbox is clicked. Note in the code how the true clause of the If statement resets the parameters m and b to their default values and sets the reset parameter to False whenever the reset checkbox is clicked on. If you watch the reset checkbox carefully you will see a check appear and immediately disappear as the true clause of the If statement is evaluated.

Note how in the If statement it is not necessary to use a condition such as reset==True . Stating the parameter name reset is sufficient since the parameter itself evaluates to either True or False.

• Add a reset checkbox control and an If statement at the beginning of the manipulate body to provide reset functionality for the manipulate controls.

Manipulate[
If[reset,{m,b,reset}={1,2,False}];
 Plot[m x+b,{x,-10,10},PlotRange->10,
PlotStyle->{Thick,Red},
AspectRatio->Automatic,AxesOrigin->{0,0},
GridLines->{Range[-10,10],Range[-10,10]},GridLinesStyle->GrayLevel[0.9],
BaseStyle->14],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"y–intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
{{reset,False},{False,True}},
ControlPlacement->Left]

Now add a grid checkbox to the list of manipulate parameters and edit the GridLines option in the Plot command to display gridlines when the grid checkbox is checked (True) and not display gridlines when the checkbox is not checked (False). Note how Delimiter was inserted in the list of manipulate parameters and what its affect is in the control area of the manipulate panel.

• Add a grid checkbox control and an If statement in the GridLines option.

Manipulate[
If[reset,{m,b,reset}={1,2,False}];
 Plot[m x+b,{x,-10,10},PlotRange->10,
PlotStyle->{Thick,Red},
AspectRatio->Automatic,AxesOrigin->{0,0},
GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],GridLinesStyle->GrayLevel[0.9],
BaseStyle->14],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"y–intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
Delimiter,
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

The visualization at the beginning of this section displays a purple point at the location where the line intercepts the vertical axis. The Plot command cannot be used to display graphic primitives such as points, line segments, circles, disks, arrows, and polygons so we use the Graphics and Show commands to plot the purple point and combine the point plot with the plot of the linear function. Add a checkbox control named showintercept that toggles the purple point on and off.

• The PlotRange, AspectRatio, BaseStyle, AxesOrigin, GridLines, and GridLinesStyle options that were options in the original Plot command have been moved to the Show command leaving only the PlotStyle option in the Plot command. 
• The Style command has been used to set the text "Where is the y-intercept?" in a boldface 12 point font and a second Delimiter has been added — strings specified as manipulate controls are treated as labels in the manipulate panel. 
• The showintercept parameter has been added to the initial If statement so it is set to False when the reset checkbox is clicked on. 
• The purple point is created using the graphic directives Purple and AbsolutePointSize along with the graphic primitive Point.

Look carefully at the Graphics command that has been added to the manipulate body and take special note of the true and false clauses of the If statement inside the Graphics command. If the checkbox showintercept is not checked (False), then the statement evaluates to Black and if showintercept is checked (True), then the statement evaluates to {Purple, AbsolutePointSize[7], Point[{0, b}]}.

Graphics[{
	If[showintercept, 
		(*T*){Purple, AbsolutePointSize[9], Point[{0, b}]}, 
		(*F*)Black]}]

If the If statement did not contain a false clause, then the Graphics command would produce the error message Null is not a Graphics primitive or directive. By simply adding a trivial false clause, in this case Black, the Graphics command does not produce an error message.

Manipulate[
If[reset,{m,b,showintercept,reset}={1,2,False,False}];
Show[
{ Plot[m x+b,{x,-10,10},PlotStyle->{Thick,Red}],
Graphics[{
If[showintercept,
(*T*){Purple,AbsolutePointSize[8],Point[{0,b}]},
(*F*)Black]}]},
PlotRange->10,AspectRatio->Automatic,BaseStyle->14,
AxesOrigin->{0,0},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],
GridLinesStyle->GrayLevel[0.9]],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"y–intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
Delimiter,
Style["Where is the y–intercept?",Bold,12],
{{showintercept,False,"show"},{False,True}},
Delimiter,
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Problem

Create the manipulate that is shown in the following problem statement.

Find values of a, b, and c so that the graph of y=a (x^2)+b x+c passes through the three points (-1,1), (1,6), and (2,7). 
({{({{}})}})

Workspace

Manipulate Solution ... Sneak a peek only if you are willing to admit defeat \[FreakedSmiley]

Manipulate[
If[reset,{a,b,c,reset}={1,0,0,False}];
Show[{
Plot[a (x^2)+b x+c,{x,-10,10},PlotStyle->{Thick,Red}],
Graphics[
{AbsolutePointSize[5],
Point[{-1,1}],Point[{1,6}],Point[{2,7}]}]},
PlotRange->10,AspectRatio->Automatic,BaseStyle->14,
GridLines->{Range[-10,10],Range[-10,10]},
GridLinesStyle->GrayLevel[0.9]],
{{a,1},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,0},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
{{c,0},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
{{reset,False},{False,True}},
ControlPlacement->Left]

Problem

Create the manipulates shown. The circle (x^2)+(y^2)=1 and hyperbola (x^2)-(y^2)=1 are plotted using the ContourPlot command.

({{({{Trigonometric Functions, Hyperbolic Functions}, {, }, {(cos(t),-sin(t)) and (cos(t),sin(t)), (cosh(t),-sinh(t)) and (cosh(t),sinh(t))}})}})

Workspace

Manipulate Solution ... Sneak a peek only if you are willing to admit defeat \[FreakedSmiley]

Manipulate[
Show[{
ContourPlot[(x^2)+(y^2)==1,{x,-2,2},{y,-2,2},MaxRecursion->2,Axes->True,Frame->False],
Graphics[{
AbsolutePointSize[6],
Red,
Point[{Cos[t],Sin[t]}],
Blue,
Point[{Cos[t],-Sin[t]}]}]},ImageSize->3*72],
{{t,0},-3.1,3.1,.1,Appearance->"Labeled"}]

Manipulate[
Show[{
ContourPlot[(x^2)-(y^2)==1,{x,-5,5},{y,-5,5},MaxRecursion->2,Axes->True,Frame->False],
Plot[{x,-x},{x,-5,5},PlotStyle->{{Gray,Dashed}}],
Graphics[{
AbsolutePointSize[6],
Red,
Point[{Cosh[t],Sinh[t]}],
Blue,
Point[{Cosh[t],-Sinh[t]}]}]},ImageSize->3*72],
{{t,0},-3.1,3.1,0.1,Appearance->"Labeled"}]

Section 3. Distance between two points

Manipulate controls shown in this example

Locator
		• Initial value specified
		• Increment value specified
		• Arbitrary symbol used for locator
	Slider2D
		• Initial value specified
		• Enabled and disabled with Enabled option
	Checkbox

Step by step process for building the manipulate

The basic picture can be created using the Graphics command with options specified for PlotRange, GridLines, GridLinesStyle, Axes, Frame, and FrameTicks.

Graphics[{Thick,Red,Line[{{-2,-1},{2,4}}]},
PlotRange->{{-10,10},{-10,10}},
GridLines->{Range[-10,10],Range[-10,10]},
GridLinesStyle->GrayLevel[0.9],Axes->True,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}}]

Make it dynamic by wrapping Manipulate[ ] around the Graphics command and specifying locator controls for the two points.

The simplest syntax for a locator control is {name,{xmin,ymin},{xmax,ymax},Locator}.

Manipulate[
Graphics[{Thick,Red,Line[{a,b}]},
PlotRange->{{-10,10},{-10,10}},
GridLines->{Range[-10,10],Range[-10,10]},
GridLinesStyle->GrayLevel[0.9],Axes->True,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}}],
{a,{-10,-10},{10,10},Locator},
{b,{-10,-10},{10,10},Locator}]

It is immediately apparent that initial values for the locators need to be specified so that both locators are clearly visible on the plot. Furthermore, increments should be specified for each locators direction control to ensure the locators "snap" to integer coordinates. To demonstrate that locators can be represented by any symbol, we will use for the b locator a large purple point using the character FilledCircle ( EscfciEsc ) — any character can be used to represent a locator's position.

The complete syntax for a locator control is 
{{name,{startx,starty}},{xmin,ymin},{xmax,ymax},{Δx,Δy},Locator,options}.

Manipulate[
Graphics[{Thick,Red,Line[{a,b}]},
PlotRange->{{-10,10},{-10,10}},
GridLines->{Range[-10,10],Range[-10,10]},
GridLinesStyle->GrayLevel[0.9],Axes->True,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}}],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]}]

It is surprising how often students think of the distance between two points in terms of the memorized formula  d=(Sqrt[((((Subscript[x, 2])-(Subscript[x, 1])))^2)+((((Subscript[y, 2])-(Subscript[y, 1])))^2)])  rather than thinking of the distance as being the hypotenuse of a right triangle. Thus, it would be nice to give users a visual hint that strongly suggests the right triangle interpretation of distance rather than the memorized formula idea. This can be added with a checkbox control and an If statement inside the Graphics command.

• Add a hint checkbox parameter and an If statement to the Graphics body. The option ControlPlacement->Left as been added to the end of the parameter list so the checkbox and subsequent controls will appear on the left side of the manipulate panel.

Look carefully at the If statement added inside Graphics command that has been added to the manipulate body and take special note of the true and false clauses. If the parameter hint is not selected (False), then the statement evaluates to Black and if hint is selected (True) then the statement evaluates to {Blue, Line[{a, b {1, 0} + a {0, 1}, b}]}.

If[hint,
 (*T*){Blue, Line[{a, b {1, 0} + a {0, 1}, b}]},
 (*F*)Black]

If the If statement did not contain a false clause, then the Graphics command would produce the error message Null is not a Graphics primitive or directive. By simply adding a trivial false clause, in this case Black, the Graphics command does not produce an error message.

Manipulate[
Graphics[{Thick,Red,Line[{a,b}],
If[hint,
(*T*){Blue,Line[{a,b{1,0}+a{0,1},b}]},
(*F*)Black]},
PlotRange->{{-10,10},{-10,10}},
GridLines->{Range[-10,10],Range[-10,10]},
GridLinesStyle->GrayLevel[0.9],Axes->True,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}}],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
ControlPlacement->Left]

Add a grid checkbox to toggle gridlines on and off by controlling an If statement for the GridLines graphics option and a reset checkbox to reset selected controls to initial states.

Manipulate[
If[reset,{a,b,hint,reset}={{-2,-1},{2,4},False,False}];
Graphics[{Thick,Red,Line[{a,b}],
If[hint,
(*T*){Blue,Line[{a,b{1,0}+a{0,1},b}]},
(*F*)Black]},
PlotRange->{{-10,10},{-10,10}},
GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],
GridLinesStyle->GrayLevel[0.9],Axes->True,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}}],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Add an answer checkbox to control the display of the computed distance between the two points. Begin by displaying the distance using the PlotLabel option for the Graphics command and display both the exact distance and a numeric approximation in red to visually connect the distance computed with the red line segment. The Row command is used to combine the exact distance, approximation symbol ≈, and the numeric approximation into one entity to be displayed (the Rationalize command ensures the radicand does not contain a decimal point). When the answer checkbox is not selected the PlotLabel is None.

Manipulate[
If[reset,{a,b,hint,answer,reset}={{-2,-1},{2,4},False,False,False}];
Graphics[{
Thick,Red,
Line[{a,b}],
If[hint,
(*T*){Blue,Line[{a,b{1,0}+a{0,1},b}]},
(*F*)Black]},
Axes->True,PlotRange->{{-10,10},{-10,10}},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],GridLinesStyle->GrayLevel[0.9],Axes->False,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}},BaseStyle->13,
PlotLabel->If[answer,
(*T*)
Row[{
Style[√(Rationalize[(a-b).(a-b)]),Red]," ≈ ",
Style[N[(Sqrt[(a-b).(a-b)])],Red]}],
(*F*)
None]],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
{{answer,False},{False,True}},
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Selecting the answer checkbox will display the computed distance as intended and unselecting the checkbox will "hide" the distance. Unfortunately, there is a visual problem with our implementation ... watch carefully as the answer checkbox is selected and unselected ... do you see a resizing of the display area of the manipulate panel? This is not visually appealing and occurs because the vertical size of the two plot labels in the If statement differ. To ensure the vertical size of the two labels are identical we specify a structure that is invisible but whose vertical size can be controlled and is present in both the true and false clause of the plot label construct. This is implemented using Column[{""},ItemSize->{0,1.75}].

Manipulate[
If[reset,{a,b,hint,answer,reset}={{-2,-1},{2,4},False,False,False}];
Graphics[{
Thick,Red,
Line[{a,b}],
If[hint,{Blue,Line[{a,b{1,0}+a{0,1},b}]},Black]},
Axes->True,PlotRange->{{-10,10},{-10,10}},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],GridLinesStyle->GrayLevel[0.9],
Axes->False,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}},BaseStyle->13,
PlotLabel->If[answer,
(*T*)
Row[{
Style[√(Rationalize[(a-b).(a-b)]),Red]," ≈ ",
Style[N[(Sqrt[(a-b).(a-b)])],Red],Column[{""},ItemSize->{0,1.75}]
}],
(*F*)
Column[{""},ItemSize->{0,1.75}]]],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
{{answer,False},{False,True}},
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Displaying the computed distance as a plot label is not the only possible solution. We now demonstrate how to display the computed distance using the graphic primitive Text at the point (-9,9).

Manipulate[
If[reset,{a,b,hint,answer,reset}={{-2,-1},{2,4},False,False,False}];
Graphics[{
Thick,Red,
Line[{a,b}],
If[hint,{Blue,Line[{a,b{1,0}+a{0,1},b}]},Black],
If[answer,
(*T*)
 Text[Row[{Style[√(Rationalize[(a-b).(a-b)]),Red]," ≈ ",
Style[N[(Sqrt[(a-b).(a-b)])],Red]}],{-9,9},{-1,0}],
(*F*)Black]},
Axes->True,PlotRange->{{-10,10},{-10,10}},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],GridLinesStyle->GrayLevel[0.9],
Axes->False,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}},BaseStyle->13],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
{{answer,False},{False,True}},
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

In the previous example we fixed the location of the computed distance at the point (-9,9). The coordinate at which the answer is displayed can be controlled with a parameter configured as Slider2D control.

Add a textlocation parameter (Slider2D) that is enabled when answer is checked and replace {-9,9} in the Text primitive with textlocation.

Manipulate[
If[reset,{a,b,hint,answer,reset}={{-2,-1},{2,4},False,False,False}];
Graphics[{
Thick,Red,
Line[{a,b}],
If[hint,{Blue,Line[{a,b{1,0}+a{0,1},b}]},Black],
If[answer,
(*T*)
Text[Row[{Style[√(Rationalize[(a-b).(a-b)]),Red]," ≈ ",
Style[N[(Sqrt[(a-b).(a-b)])],Red]}],textlocation,{-1,0}],
(*F*)Black]},
Axes->True,PlotRange->{{-10,10},{-10,10}},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],GridLinesStyle->GrayLevel[0.9],
Axes->False,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}},BaseStyle->13],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
{{answer,False},{False,True}},
{{textlocation,{-9,9},""},{-9,-9},{5,9},Enabled:>answer,ImageSize->Tiny},
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

While the Slider2D in the last example is entertaining, it would better if the text location were determined programmatically and always be located at the midpoint of the red line segment.

Our final modification removes the textlocation parameter specification, removes textlocation from the location coordinate of the Text primitive, and changes the location for the text to be the midpoint of the red line segment with an appropriated modification of the alignment parameter for the Text primitive.

Manipulate[
If[reset,{a,b,hint,answer,reset}={{-2,-1},{2,4},False,False,False}];
Graphics[{
Thick,Red,
Line[{a,b}],
If[hint,{Blue,Line[{a,b{1,0}+a{0,1},b}]},Black],
If[answer,
(*T*)
Text[Row[{Style[√(Rationalize[(a-b).(a-b)]),Red]," ≈ ",
Style[N[(Sqrt[(a-b).(a-b)])],Red]}],(a+b)/2,{1.25,-1}],
(*F*)Black]},
Axes->True,PlotRange->{{-10,10},{-10,10}},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],GridLinesStyle->GrayLevel[0.9],
Axes->False,Frame->True,
FrameTicks->{{Range[-10,10],None},{Range[-10,10],None}},BaseStyle->13],
{{a,{-2,-1}},{-10,-10},{10,10},{1,1},Locator,Appearance->Automatic},
{{b,{2,4}},{-10,-10},{10,10},{1,1},Locator,Appearance->Style["●",Purple,14]},
{{hint,False},{False,True}},
{{answer,False},{False,True}},
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Section 4. Intercept of tangent line

Problem

At which, if any, locations x=c on the graph of p(x)=(x^3)-2x+3 does the tangent line pass through the origin? 

({{}})

Solution

Begin by finding the equation of the tangent line where x=c. The slope of the tangent line where x=c is p'(c) and the point on the curve that the line passes through is (c,p(c)). Using the point-slope form for the equation of the line:

({{({{y-(Subscript[y, 1])=m(x-(Subscript[x, 1]))}, {y-p(c)=p'(c)(x-c)}, {y=p'(c)(x-c)+p(c)}, {y=p'(c)x-p'(c)c+p(c)}, {y=(Overscript[(Overscript[(3(c^2)-2), ⏞]), slope])x(Overscript[(Overscript[-(3(c^2)-2)c+((c^3)-2c+3), ⏞]), y-intercept])}})}})

You can see in the manipulate how the tangent line (red) to the graph at the point (c,p(c))(red) moves as c is modified and also how the y-intercept of the tangent line (purple point) depends on c as well.

We are looking for the value of c for which the blue point is located at the origin so we need so solve the equation

({{({{(Overscript[(Overscript[({{-(3(c^2)-2)c+((c^3)-2c+3)}}), ⏞]), y-intercept])=0}, {3-2 (c^3)=0}, {c=((3/2)^(1/3))≈1.1447142425533319`}})}})

This can be visually confirmed using the manipulate.

Manipulate controls shown in this example

Locator
		• Initial value specified
		• Restricted to moving along the horizontal axis.
		• Hidden
	Slider2D
		• Initial value specified

Step-by-step process

The basic picture can be created by defining the function p(x), assigning a value to the constant c, and then using the Plot command.

p[x_]:=(x^3)-2x+3
c=-1.2;
Plot[{p[x],p'[c](x-c)+p[c]},{x,-2,2},PlotRange->{-2,7},PlotStyle->{{Thick,Blue},Red}]

We make this dynamic by wrapping Manipulate around the commands, assigning c to a slider control, and using Module to ensure our definition of p is local to the manipulate body.

Manipulate[
Module[{p},
p[x_]:=(x^3)-2x+3;
Plot[{p[x],p'[c](x-c)+p[c]},{x,-2,2},PlotRange->{-2,7},PlotStyle->{{Thick,Blue},Red}]],
{{c,-1.2},-1.5,1.5}]

Add a red point at (c,f(c)) and a purple point at (0,-p'(c)c+p(c)) using the Show command to join together the output of Plot and the output of a Graphics command. The PlotRange option is moved from the Plot command to the Show command.

Manipulate[
Module[{p},
p[x_]:=(x^3)-2x+3;
Show[{
Plot[{p[x],p'[c](x-c)+p[c]},{x,-2,2},PlotStyle->{{Thick,Blue},Red}],
Graphics[{
AbsolutePointSize[8],
Purple,Point[{0,-p'[c]c+p[c]}],
Red,Point[{c,p[c]}]
}]
},PlotRange->{-2,7},BaseStyle->12]
],
{{c,-1.2},-1.5,1.5}]

Add a text structure giving the current value of c together with an arrow point from the text to the horizontal axis that moves left and right as c varies. The arrow is created using the Arrow graphic primitive.

Manipulate[
Module[{p},
p[x_]:=(x^3)-2x+3;
Show[{
Plot[{p[x],p'[c](x-c)+p[c]},{x,-2,2},PlotStyle->{{Thick,Blue},Red}],
Graphics[{
AbsolutePointSize[8],
Purple,Point[{0,-p'[c]c+p[c]}],
Red,Point[{c,p[c]}],
Arrow[{{c,-1.25},{c,0}}],
Style[Text[Row[{"c = ",Round[c,0.01]}],{c,-1.75}],16]
}]
},PlotRange->{-2,7},BaseStyle->12]
],
{{c,-1.2},-1.5,1.5}]

Replace the scrollbar used for the parameter c with a cLocator locator parameter that is restricted to move along the horizontal axis. The first coordinate of the cLocator gives what we previously called c, thus, we define c to be a local variable and assign it to be the first coordinate of the new  cLocator.

Manipulate[
Module[{c,p},
c=cLocator[[1]];
p[x_]:=(x^3)-2x+3;
Show[{
Plot[{p[x],p'[c](x-c)+p[c]},{x,-2,2},PlotStyle->{{Thick,Blue},Red}],
Graphics[{
AbsolutePointSize[8],
Purple,Point[{0,-p'[c]c+p[c]}],
Red,Point[{c,p[c]}],
Arrow[{{c,-1.25},{c,0}}],
Style[Text[Row[{"c = ",Round[c,0.01]}],{c,-1.75}],16]
}]
},PlotRange->{-2,7},BaseStyle->12]
],
{{cLocator,{-1.2,0}},{-1.5,0},{1.5,0},Locator}]

Try to move the locator off the horizontal axis and notice how it only moves left and right. We can take advantage of this behavior by hiding the locator completely with the Appearance->None option for the locator and thereby tricking the user into thinking that they are moving the arrow left and right, or moving the red point along the curve, or even moving the text since the horizontal location of the mouse is all that is important.

Manipulate[
Module[{c,p},
c=cLocator[[1]];
p[x_]:=(x^3)-2x+3;
Show[{
Plot[{p[x],p'[c](x-c)+p[c]},{x,-2,2},PlotStyle->{{Thick,Blue},Red}],
Graphics[{
AbsolutePointSize[8],
Purple,Point[{0,-p'[c]c+p[c]}],
Red,Point[{c,p[c]}],
Arrow[{{c,-1.25},{c,0}}],
Style[Text[Row[{"c = ",Round[c,0.01]}],{c,-1.75}],16]
}]
},PlotRange->{-2,7},BaseStyle->12]
],
{{cLocator,{-1.2,0}},{-1.5,0},{1.5,0},Locator,Appearance->None}]

Section 5. Visualizing the slope of a line

We return to the earlier slope/intercept manipulate and add features to emphasize a graphical interpretation of the slope of the line.

The original manipulate

Manipulate[
If[reset,{m,b,showintercept,reset}={1,2,False,False}];
Show[
{ Plot[m x+b,{x,-10,10},PlotStyle->{Thick,Red}],
Graphics[{
If[showintercept,
(*T*){Purple,AbsolutePointSize[10],Point[{0,b}]},
(*F*)Black]}]},
PlotRange->10,AspectRatio->Automatic,BaseStyle->14,
AxesOrigin->{0,0},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],
GridLinesStyle->GrayLevel[0.9]],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"y–intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
Delimiter,
Style["Where is the y–intercept?",Bold,12],
{{showintercept,False,"show"},{False,True}},
Delimiter,
{{grid,False},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Manipulate controls used in this example

SliderBar
		• Initial value specified
		• Alternate text label specification
		• Increment value specified
		• Numeric value shown with Appearance->"Labeled" option
		• Size modified with ImageSize->Small option
		• Enabled & disabled with Enabled option
	Checkbox
		• Alternate text label specification
		• Enabled & disabled with Enabled option
	Locator
		• Initial value specified
		• Restricted to moving along the horizontal axis.
		• Hidden
	Delimiter and arbitrary formatted text

Step-by-step process

Additional graphics objects to help users visualize the slope of the line are toggled on and off with a showrunrise checkbox and controlled by a run scrollbar. The new scrollbar will be enabled only when the showrunrise checkbox is selected and will be disabled otherwise.

• The option Enabled:>showrunrise is added to the run scrollbar so it will be enabled only when the showrunrise checkbox is selected.
• The showrunrise and run parameters have been added to the initial If statement so they are set False and 1 when the reset checkbox is clicked on.
• The points and arrows are created using the graphic directives Blue, AbsoluteThickness, Arrowheads, and AbsolutePointSize together with the graphic primitives Arrow and Point.

Manipulate[
If[reset,{m,b,showintercept,showrunrise,run,reset}={1,2,False,False,1,False}];
Show[{
Plot[m x+b,{x,-10,10},PlotStyle->{Thick,Red}],
Graphics[{
If[showintercept,
(*T*){Purple,AbsolutePointSize[10],Point[{0,b}]},
(*F*)Black],
If[showrunrise,
(*T*)
{Blue,AbsoluteThickness[1],Arrowheads[Medium],
Arrow[{{0,b},{run,b}}],
Arrow[{{run,b},{run,b+m(run)}}],
AbsolutePointSize[6],Red,
Point[{0,b}],
Point[{run,b+m(run)}]},
(*F*)Black]
}]},
PlotRange->10,AspectRatio->Automatic,BaseStyle->14,
AxesOrigin->{0,0},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],
GridLinesStyle->GrayLevel[0.9]],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
Delimiter,
Style["Where is the y–intercept?",Bold,12],
{{showintercept,False,"show"},{False,True}},
Delimiter,
Style["What is the slope?",Bold,12],
{{showrunrise,False,"show"},{False,True}},
{{run,1},-10,10,0.1,Appearance->"Labeled",ImageSize->Small,Enabled:>showrunrise},
Delimiter,
{{grid,False,"grid"},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

It would be nice to display the numeric value of the run and associated rise values right next to the blue arrows showing these quantities. This can be accomplished with a label checkbox, an If statement in the graphics body, and a couple of Text graphic primitives. The display of the run and rise numeric values are suppressed if the run is less than 1, or the slope of the line is 0, for readability concerns.

• The text labels are created using the Text graphic primitive where the third argument of Text is used to align the text either above, below, to the right, or to the left of the coordinate given as the second argument (note the use of the Sign function for alignment). The Text command is wrapped by a Style command in order set the font size for the text labels to 11 points. 
• The label parameter has been added to the initial If statement so it is set to False when the reset checkbox is clicked on.

Manipulate[
If[reset,{m,b,showintercept,showrunrise,run,label,reset}={1,2,False,False,1,False,False}];
Show[{
Plot[m x+b,{x,-10,10},PlotStyle->{Thick,Red}],
Graphics[{
If[showintercept,
(*T*){Purple,AbsolutePointSize[10],Point[{0,b}]},
(*F*)Black],
If[showrunrise,
(*T*)
{Blue,AbsoluteThickness[1],Arrowheads[Medium],
Arrow[{{0,b},{run,b}}],
Arrow[{{run,b},{run,b+m(run)}}],
AbsolutePointSize[6],Red,
Point[{0,b}],
Point[{run,b+m(run)}]},
(*F*)Black],
If[label&&Abs[run]≥1&&showrunrise&&m=!=0,
(*T*)
{Blue,
Style[Text[run,{0.4*run,b},{0,Sign[m*run]1.5}],11],
Style[Text[m*run,{run,b+m(0.4run)},{-Sign[run]1.8,0}],11]},
(*F*)Black]
}]},
PlotRange->10,AspectRatio->Automatic,BaseStyle->14,
AxesOrigin->{0,0},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],
GridLinesStyle->GrayLevel[0.9]],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
Delimiter,
Style["Where is the y–intercept?",Bold,12],
{{showintercept,False,"show"},{False,True}},
Delimiter,
Style["What is the slope?",Bold,12],
{{showrunrise,False,"show"},{False,True}},
{{run,1},-10,10,0.1,Appearance->"Labeled",ImageSize->Small,Enabled:>showrunrise},
{{label,False},{False,True},Enabled:>showrunrise},
Delimiter,
{{grid,False,"grid"},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

We can make the point on the line where the run and rise visualization begins move to any horizontal value between -10 and 10. This can be accomplished with a locator control that is hidden from view, an arrow pointing at the horizontal value being used, and a text label which reports the current location. The horizontal location can be controlled by clicking on the text label (or the red arrow) and moving it left and right.

Manipulate[
If[reset,{m,b,showintercept,showrunrise,run,label,xValue,reset}={1,2,False,False,1,False,{0,0},False}];
Show[{
Plot[m x+b,{x,-10,10},PlotStyle->{Thick,Red}],
Graphics[{
If[showintercept,
(*T*){Purple,AbsolutePointSize[10],Point[{0,b}]},
(*F*)Black],
If[showrunrise,
(*T*)
{Red,
Arrow[{{xValue[[1]],-1.5},{xValue[[1]],0}}],
Style[Text[Row[{"x = ",xValue[[1]]}],{xValue[[1]],-1.75},{-1,0}],Red],
Blue,AbsoluteThickness[1],Arrowheads[Medium],
Arrow[{{xValue[[1]],b+m*xValue[[1]]},{xValue[[1]]+run,b+m*xValue[[1]]}}],
Arrow[{{xValue[[1]]+run,b+m*xValue[[1]]},{xValue[[1]]+run,b+m(xValue[[1]]+run)}}],
AbsolutePointSize[6],Red,
Point[{xValue[[1]],b+m*xValue[[1]]}],
Point[{xValue[[1]]+run,b+m(xValue[[1]]+run)}]},
(*F*)Black],
If[label&&Abs[run]≥1&&showrunrise&&m=!=0,
(*T*)
{Blue,
Style[Text[run,{xValue[[1]]+0.4*run,b+m*xValue[[1]]},{0,Sign[m*run]1.5}],11],
Style[Text[m*run,{xValue[[1]]+run,b+m(xValue[[1]]+0.4run)},{-Sign[run]1.8,0}],11]},
(*F*)Black]
}]},
PlotRange->10,AspectRatio->Automatic,BaseStyle->14,
AxesOrigin->{0,0},GridLines->If[grid,{Range[-10,10],Range[-10,10]},None],
GridLinesStyle->GrayLevel[0.9]],
{{m,1,"slope"},-5,5,0.1,Appearance->"Labeled",ImageSize->Small},
{{b,2,"intercept"},-10,10,0.1,Appearance->"Labeled",ImageSize->Small},
Delimiter,
Style["Where is the y–intercept?",Bold,12],
{{showintercept,False,"show"},{False,True}},
Delimiter,
Style["What is the slope?",Bold,12],
{{showrunrise,False,"show"},{False,True}},
{{run,1},-10,10,0.1,Appearance->"Labeled",ImageSize->Small,Enabled:>showrunrise},
{{label,False},{False,True},Enabled:>showrunrise},
{{xValue,{0,0}},{-10,0},{10,0},0.1,Locator,Enabled:>showrunrise,Appearance->None},
Delimiter,
{{grid,False,"grid"},{False,True}},
{{reset,False},{False,True}},
ControlPlacement->Left]

Section 6. Derivatives of trigonometric functions

Manipulate controls shown in this example

SliderBar
		• Initial value specified
	SetterBar and RadioButtonBar
		• Select function to be plotted
	CheckboxBar
		• Select plot options
	Checkbox

We begin by demonstrating a technique which uses a SetterBar to select one of several functions to work with. The SetterBar selection is also used to set the PlotRange and Exclusions options for the Plot command.

Manipulate[
Module[{f},
f[x_]:={Sin[x],Cos[x],Tan[x]};
Plot[
f[x][[fNumber]],
{x,-2π,2π},
PlotRange->If[fNumber==3,10,3/2],
Exclusions->If[fNumber==3,{-3π/2,-π/2,π/2,3π/2},None],
ImageSize->7*72,BaseStyle->13,AspectRatio->1/2]],
{{fNumber,1,"function"},{1->" sine ",2->" cosine ",3->" tangent "},SetterBar}]

Add a SliderBar control that moves a point along the curve. Move the ImageSize, BaseStyle, and AspectRatio from Plot to Show.

Manipulate[
Module[{f},
f[x_]:={Sin[x],Cos[x],Tan[x]};
Show[{
Plot[
f[x][[fNumber]],
{x,-2π,2π},
PlotRange->If[fNumber==3,10,3/2],
Exclusions->If[fNumber==3,{-3π/2,-π/2,π/2,3π/2},None]],
Graphics[{AbsolutePointSize[7],Blue,Point[{xValue,f[xValue][[fNumber]]}]}]},
ImageSize->7*72,BaseStyle->13,AspectRatio->1/2]],
{{fNumber,1,"function"},{1->" sine ",2->" cosine ",3->" tangent "},SetterBar},
{{xValue,0,"x"},-2π,2π}]

Add a CheckboxBar control named plotoptions which contains checkboxes ( members ) for plotting the first derivative, plotting the second derivative, and toggling the tick marks on and off. The command MemberQ[parameter,memberName] is used to determine if the associated member checkbox is selected.

Manipulate[
Module[{f},
f[x_]:={Sin[x],Cos[x],Tan[x]};
Show[{
Plot[
{f[x][[fNumber]],
If[MemberQ[plotoptions,first],f'[x][[fNumber]]],
If[MemberQ[plotoptions,second],f''[x][[fNumber]]]},
{x,-2π,2π},
PlotRange->If[fNumber==3,10,3/2],
Exclusions->If[fNumber==3,{-3π/2,-π/2,π/2,3π/2},None],
Ticks->If[MemberQ[plotoptions,ticks],{Range[-2π,2π,π/4],If[fNumber==3,Range[-10,10,2],Range[-2,2,0.5]]},None],
PlotStyle->{{Thick,Blue},Red,Brown}],
Graphics[{AbsolutePointSize[7],Blue,Point[{xValue,f[xValue][[fNumber]]}]}]},
ImageSize->7*72,BaseStyle->13,AspectRatio->1/2]],
{{fNumber,1,"function"},{1->" sine ",2->" cosine ",3->" tangent "},SetterBar},
{{xValue,0,"x"},-2π,2π},
{{plotoptions,{},""},{first->Style[" first derivative ",Red],second->Style[" second derivative ",Brown],ticks->" show ticks "},CheckboxBar}]

Add points on the first and second derivative plots whose position is controlled by the xValue slider control. Finish by adding a reset checkbox  located at the bottom of the manipulate panel.

Manipulate[
If[reset,{xValue,plotoptions,reset}={0,{},False}];
Module[{f},
f[x_]:={Sin[x],Cos[x],Tan[x]};
Show[{
Plot[
{f[x][[fNumber]],
If[MemberQ[plotoptions,first],f'[x][[fNumber]]],
If[MemberQ[plotoptions,second],f''[x][[fNumber]]]},
{x,-2π,2π},
PlotRange->If[fNumber==3,10,3/2],
Exclusions->If[fNumber==3,{-3π/2,-π/2,π/2,3π/2},None],
Ticks->If[MemberQ[plotoptions,ticks],{Range[-2π,2π,π/4],If[fNumber==3,Range[-10,10,2],Range[-2,2,0.5]]},None],
PlotStyle->{{Thick,Blue},Red,Brown}],
Graphics[{
AbsolutePointSize[7],Blue,Point[{xValue,f[xValue][[fNumber]]}],
Red,If[MemberQ[plotoptions,first],Point[{xValue,f'[xValue][[fNumber]]}],Black],
Brown,If[MemberQ[plotoptions,second],Point[{xValue,f''[xValue][[fNumber]]}],Black]
}]},
ImageSize->7*72,BaseStyle->13,AspectRatio->1/2]],
{{fNumber,1,"function"},{1->" sine ",2->" cosine ",3->" tangent "},SetterBar},
{{xValue,0,"x"},-2π,2π},
{{plotoptions,{},""},{first->Style[" first derivative ",Red],second->Style[" second derivative ",Brown],ticks->" show ticks "},CheckboxBar},
{{reset,False},{False,True},ControlPlacement->Bottom}]

Extension

Additional items have been added to the following manipulate. The code is hidden below — if you are looking for a challenge you should try to extend this section's manipulate yourself.

Workspace

Manipulate Solution ... Sneak a peek only if you are willing to admit defeat \[FreakedSmiley]

Manipulate[
If[reset,{xValue,plotoptions,reset}={0,{},False}];
Module[{f},
f[x_]:={Sin[x],Cos[x],Tan[x]};
Show[{
Plot[
{f[x][[fNumber]],
If[MemberQ[plotoptions,first],f'[x][[fNumber]]],
If[MemberQ[plotoptions,second],f''[x][[fNumber]]]},
{x,-2π,2π},
PlotRange->If[fNumber==3,10,3/2],Ticks->If[MemberQ[plotoptions,ticks],{Range[-2π,2π,π/4],If[fNumber==3,Range[-10,10,2],Range[-2,2,0.5]]},None],PlotStyle->{{Thick,Blue},Lighter[Red],Brown},
Exclusions->If[fNumber==3,{-3π/2,-π/2,π/2,3π/2},None]],
Graphics[{
AbsolutePointSize[7],Blue,Point[{xValue,f[xValue][[fNumber]]}],
Red,If[MemberQ[plotoptions,first],Point[{xValue,f'[xValue][[fNumber]]}],Black],
Brown,If[MemberQ[plotoptions,second],Point[{xValue,f''[xValue][[fNumber]]}],Black],
Red,Arrowheads[Medium],
Arrow[{{xValue,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]+f'[xValue][[fNumber]]}}],
If[MemberQ[plotoptions,first],
Which[
f'[xValue][[fNumber]]<0,Text[" - ",{xValue,f[xValue][[fNumber]]},{-1.5,-1}],
f'[xValue][[fNumber]]==0,Text["",{xValue,f[xValue][[fNumber]]},{0,0}],
f'[xValue][[fNumber]]>0,Text[" + ",{xValue,f[xValue][[fNumber]]},{-1.5,-1}]],
Black],
Brown,
If[MemberQ[plotoptions,second],
Which[
f''[xValue][[fNumber]]<0,Text[" ⌢ ",{xValue,f[xValue][[fNumber]]},{1.5,-1}],
f''[xValue][[fNumber]]==0,Text["",{xValue,f[xValue][[fNumber]]},{0,0}],
f''[xValue][[fNumber]]>0,Text[" ⌣ ",{xValue,f[xValue][[fNumber]]},{1.5,-1}]],
Black],
If[MemberQ[plotoptions,riserun],
{Darker[Green],Thick,
Text["1",{xValue+0.5,f[xValue][[fNumber]]},{0,1.5}],
Text[Round[f'[xValue][[fNumber]],0.01],{xValue+1,f[xValue][[fNumber]]+.5f'[xValue][[fNumber]]},{-1.5,0}],
Line[{{xValue,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]+f'[xValue][[fNumber]]}}]},
Black]
}]
},ImageSize->7*72,BaseStyle->13,AspectRatio->1/2]],
{{fNumber,1,"function"},{1->" sine ",2->" cosine ",3->" tangent "}},
{{xValue,0,"x"},-2π,2π},
{{plotoptions,{},""},
{first->Style[" first derivative ",Red],second->Style[" second derivative ",Brown],
riserun->" show run & rise",ticks->" show ticks "},ControlType->CheckboxBar},
{{reset,False},{False,True},ControlPlacement->Bottom}
]

Further examples

What can you say?

Manipulate[
If[reset,{power,fontsize,color1,color2,reset}={1,{12,12},Red,Blue,False}];
Style[Expand[(Style[x,color1,fontsize[[1]]]+Style[y,color2,fontsize[[2]]])^power],color3,othersize],
{power,1,10,1},
{{power,1},InputField},
{{power,1},{1->" power = 1 ",2->" power = 2",3->" power = 3"}},
{{power,1},{1->" power = 1 ",2->" power = 2",3->" power = 3"},PopupMenu},
{{power,1},{1->" power = 1 ",2->" power = 2",3->" power = 3"},RadioButton},
{{fontsize,{12,12},"variable size"},{6,6},{72,72},{1,1}},
{{othersize,12,"other size"},3,72},
{{color1,Red,"x color"},ColorSlider},
{{color2,Blue,"y color"},ColorSetter},
{{color3,Black,"other color"},ColorSetter},  
{{reset,False},{False,True}},ControlPlacement->Top]

Intermediate Value Theorem

Slider

by Julianne Sachs, WWCC

Manipulate[
Module[{f,fInverse,a,b,xMin,xMax,yMin,yMax},
{xMin,xMax,yMin,yMax}={-1,8,-1,8};
{a,b}={1,7};
f[x_]:=0.1(((x-4))^3)+4;
fInverse[y_]:=4+Sign[y-4](((Abs[10y-40]))^(1/3));
Show[{
Plot[f[x],{x,xMin,xMax},PlotStyle->{Blue,Thick},
Ticks->{
{{a,Style["a",Brown,Italic]},
{b,Style["b",Brown,Italic]},
{0,Column[{""},ItemSize->{Automatic,2}]},
If[ivt,
{fInverse[m],Style["c",Darker[Green],Italic]},
{0,Column[{""},ItemSize->{Automatic,2}]}]},
{{f[a],Style["f(a)",Brown,Italic]},
{f[b],Style["f(b)",Brown,Italic]},
{m,Style["M  ",Red,Italic]},
{0,Column[{""},ItemSize->{4,Automatic}]}}}],
Graphics[{
AbsolutePointSize[8],
Red,Thick,Line[{{0,f[a]},{0,f[b]}}],
Point[{0,m}],
If[ivt,
(*T*){
Blue,Point[{fInverse[m],m}],
Darker[Green],Point[{fInverse[m],0}],
Thick,Line[{{a,0},{b,0}}],
Dashed,
Arrow[{{fInverse[m],m-0.15},{fInverse[m],0}}],
Red,Line[{{0,m},{fInverse[m]-0.15,m}}],
Brown,Thin,Dashing[{}],
Line[{{a,0},{a,f[a]},{0,f[a]}}],Line[{{b,0},{b,f[b]},{0,f[b]}}],
Lighter[Brown,.7],Opacity[.3],
Polygon[{{a,0},{a,f[a]},{0,f[a]},{0,f[b]},{b,f[b]},{b,0}}]},
(*F*)Black]}]},
AspectRatio->Automatic,BaseStyle->16,PlotRange->{{xMin,xMax},{yMin,yMax}}]
],
{{m,3,"M"},1.3,6.7,ControlPlacement->Top},
{{ivt,False,"IVT"},{False,True},ControlPlacement->Top}]

Hidden locator

Manipulate[
Module[{f,fInverse,a,b,xMin,xMax,yMin,yMax,m},
{xMin,xMax,yMin,yMax}={-1,8,-1,8};
{a,b}={1,7};
m=mLocator[[2]];
f[x_]:=0.1(((x-4))^3)+4;
fInverse[y_]:=4+Sign[y-4](((Abs[10y-40]))^(1/3));
Show[{
Plot[f[x],{x,xMin,xMax},PlotStyle->{Blue,Thick},
Ticks->{
{{a,Style["a",Brown,Italic]},
{b,Style["b",Brown,Italic]},
{0,Column[{""},ItemSize->{Automatic,2}]},
If[ivt,
{fInverse[m],Style["c",Darker[Green],Italic]},
{0,Column[{""},ItemSize->{Automatic,2}]}]},
{{f[a],Style["f(a)",Brown,Italic]},
{f[b],Style["f(b)",Brown,Italic]},
{m,Style["M  ",Red,Italic]},
{0,Column[{""},ItemSize->{4,Automatic}]}}}],
Graphics[{
AbsolutePointSize[8],
Red,Thick,Line[{{0,f[a]},{0,f[b]}}],
Point[{0,m}],
If[ivt,
(*T*){
Blue,Point[{fInverse[m],m}],
Darker[Green],Point[{fInverse[m],0}],
Thick,Line[{{a,0},{b,0}}],
Dashed,
Arrow[{{fInverse[m],m-0.15},{fInverse[m],0}}],
Red,Line[{{0,m},{fInverse[m]-0.15,m}}],
Brown,Thin,Dashing[{}],
Line[{{a,0},{a,f[a]},{0,f[a]}}],Line[{{b,0},{b,f[b]},{0,f[b]}}],
Lighter[Brown,.7],Opacity[.3],
Polygon[{{a,0},{a,f[a]},{0,f[a]},{0,f[b]},{b,f[b]},{b,0}}]},
(*F*)Black]}]},
AspectRatio->Automatic,BaseStyle->16,PlotRange->{{xMin,xMax},{yMin,yMax}}]
],
{{mLocator,{0,3}},{0,1.3},{0,6.7},Locator,Appearance->None},
{{ivt,False,"IVT"},{False,True},ControlPlacement->Top}]

Secant line -> tangent line

Manipulate[
If[reset, {a, h, fNumber, plotoptions1,plotoptions2,reset} = {0.2, 1, 1, {tangent,secant},{}, False}]; 
Module[
{xMin, xMax, yMin, yMax, secantSlope, f},
{xMin,xMax,yMin,yMax}={-0.01,5,-5,5};
f[x_]:={(2(((x-1.5))^2)-10)/3,(4-3(((x-2))^2))/3,4.5-1.5x,(-12+31 x-15 (x^2)+2 (x^3))/6,(9Cos[π/2  x]+4)/3};
    secantSlope[a_,h_]:=If[h != 0, (f[a + h][[fNumber]] - f[a][[fNumber]])/h, f'[a][[fNumber]]]; 
   Show[{
Plot[f[x][[fNumber]], {x, xMin, xMax}, 
PlotRange -> {yMin, yMax}, PlotStyle -> {Black, Thick}, 
Ticks ->If[MemberQ[plotoptions2, ticks], 
(*T*){{
{a, Style["a", Italic]}, {a + h, Style["a+h", Italic]}, {0, ""}}, 
{{f[a][[fNumber]], Style["f(a)", Italic]},
 {f[a + h][[fNumber]], Style["f(a+h)", Italic]}, {0, ""}}},
(*F*)None]], 
     Graphics[{
If[MemberQ[plotoptions2, riserun]&&MemberQ[plotoptions1,secant], 
(*T*){Arrowheads[Medium],
 Darker[Green], 
Arrow[{{a, f[a][[fNumber]]}, {a + h, f[a][[fNumber]]}}],         
Arrow[{{a + h, f[a][[fNumber]]}, {a + h, f[a + h][[fNumber]]}}],Text[Style["h", Italic], {a + h/2, f[a][[fNumber]]}, {0, Sign[h]*2}], 
Text[Style["f(a+h)-f(a)", Italic], {a + h, (f[a][[fNumber]] +  f[a + h][[fNumber]])/2}, {Sign[-h]*1.5, 0}], 
Thick, 
If[MemberQ[plotoptions2,ticks],
(*T*){Line[{{a, 0.2}, {a + h, 0.2}}],
Line[{{0.05, f[a][[fNumber]]}, {0.05, f[a + h][[fNumber]]}}]},
(*F*)Black]},
 (*F*)Black], 
If[MemberQ[plotoptions1, secant], 
(*T*){Blue, 
Line[{{xMin, secantSlope[a, h]*(xMin - a) + f[a][[fNumber]]},{xMax, secantSlope[a, h]*(xMax - a) + f[a][[fNumber]]}}]}, 
(*F*)Black], 
If[MemberQ[plotoptions1, tangent], 
(*T*){Red, Thick, 
 Line[{{xMin, Derivative[1][f][a][[fNumber]]*(xMin - a) + f[a][[fNumber]]},            {xMax, Derivative[1][f][a][[fNumber]]*(xMax - a) + f[a][[fNumber]]}}]}, 
 (*F*)Black],
Black, 
AbsolutePointSize[7],
Point[{a, f[a][[fNumber]]}], 
If[MemberQ[plotoptions1, secant], 
(*T*){Lighter[Black],Point[{a + h, f[a + h][[fNumber]]}]}, 
(*F*)Black]}]}, 
 PlotRange -> {{xMin - 0.6, xMax+1}, {yMin - 1, yMax + 1}}, AxesOrigin->{0,0},
BaseStyle -> 16, ImageSize -> 6*72,GridLines -> If[MemberQ[plotoptions2, grids], {Range[xMin, xMax, 1], Range[yMin, yMax, 1]}, None], 
    GridLinesStyle -> Lighter[Gray, 0.7]]], 
{{fNumber, 1, "function"}, {1 -> " quadratic ", 2 -> " quadratic ", 3 -> " linear ", 4->" cubic ",5 -> " cosine "}, 
  ControlType -> Setter}, 
{{a, 0.2}, 0, 4}, 
{{h, 1}, -3, 3}, 
 {{plotoptions1, {tangent,secant}, ""}, {tangent -> " tangent line", secant -> " secant line"}, 
  ControlType -> CheckboxBar}, 
{{plotoptions2,{},""},
{riserun->" show secant run & rise",grids->" grid (1 by 1)",ticks->" show ticks "},ControlType->CheckboxBar},
{{reset, False}, {False, True}, ControlPlacement -> Bottom}]

Derivative trail

Slider

Manipulate[
If[reset==True,{xValue,plotoptions1,plotoptions2,reset}={0.2,{},{},False}];
Module[
{xMin,xMax,yMin,yMax,f},
{xMin,xMax,yMin,yMax}={-0.01,5,-5,5};
f[x_]:={(2(((x-1.5))^2)-10)/3,(4-3(((x-2))^2))/3,4.5-1.5x,(-12+31 x-15 (x^2)+2 (x^3))/6,(9Cos[π/2  x]+4)/3};
Show[{
Plot[f[x][[fNumber]],{x,xMin,xMax},PlotStyle->{Black,Thick}],
Plot[If[MemberQ[plotoptions1,tangent],f'[xValue][[fNumber]](x-xValue)+f[xValue][[fNumber]]],{x,xMin,xMax},PlotStyle->Lighter[Red]],
Plot[If[MemberQ[plotoptions1,derivative],f'[x][[fNumber]]],{x,xMin,xValue},PlotStyle->{Red,Thick}],
Graphics[{
Black,AbsolutePointSize[8],
Point[{xValue,f[xValue][[fNumber]]}],
Red,Thick,Arrow[{
{xValue,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]+f'[xValue][[fNumber]]}}],
Red,AbsolutePointSize[8],
Point[{xValue,f'[xValue][[fNumber]]}],
Which[
f'[xValue][[fNumber]]<0,Text[" - ",{xValue,f[xValue][[fNumber]]},{-1,-1}],
f'[xValue][[fNumber]]==0,Text["",{xValue,f[xValue][[fNumber]]},{0,0}],
f'[xValue][[fNumber]]>0,Text[" + ",{xValue,f[xValue][[fNumber]]},{-1,1}]],
Darker[Green],
If[MemberQ[plotoptions2,riserun],
(*T*)Text["1",{xValue+0.5,f[xValue][[fNumber]]},{0,1.5}],
(*F*)Black],
If[MemberQ[plotoptions2,riserun],
(*T*)Text[Round[f'[xValue][[fNumber]],0.01],{xValue+1,f[xValue][[fNumber]]+.5f'[xValue][[fNumber]]},{-1.5,0}],
(*F*)Black],
If[MemberQ[plotoptions2,riserun],
(*T*)Line[{
{xValue,f[xValue][[fNumber]]},
{xValue+1,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]+1f'[xValue][[fNumber]]}}],(*F*)Black]}]
},
PlotRange->{{xMin-0.5,xMax+1},{yMin-1,yMax+1}},AxesOrigin->{0,0},
BaseStyle->16,ImageSize->6*72,
Ticks->If[MemberQ[plotoptions2,ticks],
(*T*){
{{xValue,Style["x",Italic]}},
{{f[xValue][[fNumber]],Style["f(x)",Italic]},
{f'[xValue][[fNumber]],Style["f'(x)",Italic,Red]}}},
(*F*)None],
GridLines->If[MemberQ[plotoptions2,grids],{Range[xMin,xMax,1],Range[yMin,yMax,1]},None],
GridLinesStyle->Lighter[Gray,.7]]],
{{fNumber, 1, "function"}, {1 -> " quadratic ", 2 -> " quadratic ", 3 -> " linear ", 4->" cubic ",5 -> " cosine "}, 
ControlType->Setter},
{{xValue,0.2,"x"},0,5,.1},
{{plotoptions1,{},""},{tangent->" tangent line ",derivative->" derivative trail "},ControlType->CheckboxBar},
{{plotoptions2,{},""},
{riserun->" show run & rise",grids->" grid (1 by 1)",ticks->" show ticks "},ControlType->CheckboxBar},
{{reset,False},{False,True},ControlPlacement->Bottom},SaveDefinitions->True]

Hidden locator

Manipulate[
If[reset==True,{lpt,plotoptions1,plotoptions2,reset}={{0.2,0},{},{},False}];
Module[
{xMin,xMax,yMin,yMax,f,xValue},
{xMin,xMax,yMin,yMax}={-0.01,5,-5,5};
f[x_]:={(2(((x-1.5))^2)-10)/3,(4-3(((x-2))^2))/3,4.5-1.5x,(-12+31 x-15 (x^2)+2 (x^3))/6,(9Cos[π/2  x]+4)/3};
xValue=lpt[[1]]; 
Show[{
Plot[f[x][[fNumber]],{x,xMin,xMax},PlotStyle->{Black,Thick}],
Plot[If[MemberQ[plotoptions1,tangent],f'[xValue][[fNumber]](x-xValue)+f[xValue][[fNumber]]],{x,xMin,xMax},PlotStyle->Lighter[Red]],
Plot[If[MemberQ[plotoptions1,derivative],f'[x][[fNumber]]],{x,xMin,xValue},PlotStyle->{Red,Thick}],
Graphics[{
Black,AbsolutePointSize[8],
Point[{xValue,f[xValue][[fNumber]]}],
Red,Thick,Arrow[{
{xValue,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]+f'[xValue][[fNumber]]}}],
Red,AbsolutePointSize[8],
Point[{xValue,f'[xValue][[fNumber]]}],
Which[
f'[xValue][[fNumber]]<0,Text[" - ",{xValue,f[xValue][[fNumber]]},{-1,-1}],
f'[xValue][[fNumber]]==0,Text["",{xValue,f[xValue][[fNumber]]},{0,0}],
f'[xValue][[fNumber]]>0,Text[" + ",{xValue,f[xValue][[fNumber]]},{-1,1}]],
Darker[Green],
If[MemberQ[plotoptions2,riserun],
(*T*)Text["1",{xValue+0.5,f[xValue][[fNumber]]},{0,1.5}],
(*F*)Black],
If[MemberQ[plotoptions2,riserun],
(*T*)Text[Round[f'[xValue][[fNumber]],0.01],{xValue+1,f[xValue][[fNumber]]+.5f'[xValue][[fNumber]]},{-1.5,0}],
(*F*)Black],
If[MemberQ[plotoptions2,riserun],
(*T*)Line[{
{xValue,f[xValue][[fNumber]]},
{xValue+1,f[xValue][[fNumber]]},{xValue+1,f[xValue][[fNumber]]+1f'[xValue][[fNumber]]}}],(*F*)Black]}]
},
PlotRange->{{xMin-0.5,xMax+1},{yMin-1,yMax+1}},AxesOrigin->{0,0},
BaseStyle->16,ImageSize->6*72,
Ticks->If[MemberQ[plotoptions2,ticks],
(*T*){
{{xValue,Style["x",Italic]}},
{{f[xValue][[fNumber]],Style["f(x)",Italic]},
{f'[xValue][[fNumber]],Style["f'(x)",Italic,Red]}}},
(*F*)None],
GridLines->If[MemberQ[plotoptions2,grids],{Range[xMin,xMax,1],Range[yMin,yMax,1]},None],
GridLinesStyle->Lighter[Gray,.7]]],
{{fNumber, 1, "function"}, {1 -> " quadratic ", 2 -> " quadratic ", 3 -> " linear ", 4->" cubic ",5 -> " cosine "}, 
ControlType->Setter},
{{plotoptions1,{},""},{tangent->" tangent line ",derivative->" derivative trail "},ControlType->CheckboxBar},
{{plotoptions2,{},""},
{riserun->" show run & rise",grids->" grid (1 by 1)",ticks->" show ticks "},ControlType->CheckboxBar},
{{lpt,{0.2,0}},{0,-5},{5,5},{.1,.1},Locator,Appearance->None},
{{reset,False},{False,True},ControlPlacement->Bottom},SaveDefinitions->True]

Ellipse and tangent line

Manipulate[
If[reset,{a,b,θ,tangent,center,reset}={4,2,0,False,{0,0},False}];
Show[{
ContourPlot[((((x-center[[1]]))^2)/(a^2))+((((y-center[[2]]))^2)/(b^2))==1,{x,-10,10},{y,-10,10},MaxRecursion->2,
Axes->True,Frame->False,ContourStyle->{Thick,Blue}],
ParametricPlot[
If[tangent,Normalize[{-a Sin[θ],b Cos[θ]}]t+{a Cos[θ]+center[[1]],b Sin[θ]+center[[2]]}],
{t,-15,15},PlotStyle->Red],
Graphics[{AbsolutePointSize[8],Red,Point[{a Cos[θ]+center[[1]],b Sin[θ]+center[[2]]}]
}]
},GridLines->{Range[-10,10],Range[-10,10]},GridLinesStyle->GrayLevel[0.9],BaseStyle->14],
{{a,4},0.1,10,ImageSize->Small},
{{b,2},0.1,10,ImageSize->Small},
{{θ,0,"location"},0,2π,ImageSize->Small},
{{tangent,False,"tangent line"},{False,True}},
{{center,{0,0}},{-5,-5},{5,5},{1,1},ControlType->Locator},
{{reset,False},{False,True}},
ControlPlacement->Left]

Demonstration website

Go to demonstrations.wolfram.com and enter Schulz in the search field for additional examples.