Introduction to Manipulate

Math 213 - Math with Mathematica
Christopher Hanusa
Supplement to the tutorial “tutorial/IntroductionToManipulate” in the Documentation Center

Overview

In this tutorial, we will be following along the tutorial “tutorial/IntroductionToManipulate” in Mathematica’s Documentation Center.  We will cover the sections:

1. Manipulate Is as Easy as Table

2. Symbolic Output and Step Sizes

3. Types of Controls

4. Initial Values and Labels

5. Beautifying the Control Area

6. 2D Sliders

7. Graphics beyond Plotting

8. Locator

9. 3D Graphics

10. All Types of Output Are Supported

(Feel free to continue interacting with the tutorial to learn about saving initial conditions and using gamepads and joysticks.)

Section 1: Manipulate is as Easy as Table

Read and interact with Section 1.  Then answer the following questions.

1. Create a Manipulate command that will output the value of (x^n) for values of x that vary from -10 to 10 and values of n that vary from 0 to 8.  What do you notice as you move the sliders?  Why does it happen?

Section 2: Symbolic Output and Step Sizes

Read and interact with Section 2.  Then answer the following questions.

2. Modify your code from Question 1 to create TWO Manipulate commands:

Create one Manipulate command in which the exponents are integers from -10 to 10.

Create one Manipulate command in which you calculate integer roots of x.  (Have it calculate Square root, Cube root, Fourth root, etc., for integers 1 through 20)

Section 3. Types of Controls

Read and interact with Section 3.  Then answer the following questions.

3. Read through the Documentation Center about “ref/ControlType”.
Copy or Create one Manipulate command that generates each of the following types of control: Slider, SetterBar, PopupMenu, Checkbox.

Section 4. Initial Values and Labels

Read and interact with Section 4.  Then answer the following questions.

4a. What are the benefits of being able to specify an initial value for a Manipulate command?

4b. For the graphics object that is on input line 22  (The beginning of the code block says In[22]), click on the + box to the right of the n1 variable to open the menu that allows you to see the value that n1 is presently taking on.  Then Click the “Play” button to see how the graphic changes when the n1 variable is modified.  Use the Double Arrow to slow down the change of n1 so that you can see the pretty patterns that happen in the output as n1 changes slowly.  Choose some values of the parameters that you especially like.

Section 5. Beautifying the Control Area and Section 6. 2D Sliders

Read and interact with Sections 5 and 6.  Then answer the following questions.

5. Compare the design of the three Manipulate commands output on input lines 25, 26, 30.  Which do you think has the controls placed in a better fashion? Why? What definition of “better” are you using here?

6. Modify the Manipulate command on input line 29 to have another slider that controls the radius of the point.

Section 7. Graphics beyond Plotting

Read and interact with Section 7.  Then answer the following questions.

7a. Look at the code from input lines 32 and 33.  Dissect the code and work to understand how it works.  If you don’t understand, talk to your neighbor.

7b. Modify the code from line 32 to create the a manipulate command that does the following:

Section 8. Locator

Read and interact with Section 8.  Then answer the following questions.

Question 8.  Add a large amount of new Locators (using clicking) to the following Manipulate command and get it to spell a letter.

Manipulate[Graphics[Polygon[pts2],PlotRange->1],
{{pts2,{{0,0},{.5,0},{0,.5}}},Locator,LocatorAutoCreate->True}]

Here is an example of the letter C:

Manipulate[Graphics[Polygon[pts],PlotRange->1],
{{pts,{{0,0},{.5,0},{0,.5}}},Locator,LocatorAutoCreate->True}]

Section 9. 3D Graphics

Read and interact with Section 9.  Then answer the following questions.

9.  An interesting set of surfaces that you learn about in Math 201, Multivariable Calculus are the Quadric Surfaces, which have one of two forms: ax^2+by^2+cz^2=k or z=ax^2+by^2+k.  Use Manipulate to explore the range of possible quadric surfaces by modifying the following two pieces of code

ContourPlot3D[x^2+2y^2-3z^2==5,{x,-10,10},{y,-10,10},{z,-10,10}]

Plot3D[3x^2-4y^2+6,{x,-10,10},{y,-10,10}]

Section 10. All Types of Output Are Supported

Read and interact with Section 10.  Then answer the following questions.

10.  Modify the Mathematica code given on line 45 to change the ControlType to something different than Slider.  Do you like the new output better or worse? Why?

Selected Solutions

Question 7b

Did you try it yourself?  If not, go back and try for at least 10 minutes!

Part 1

Manipulate[

Part 2

Graphics[

Part 3

{Line[Table[{{0,i},pt},{i,-1,1,2/(n-1)}]]},

Part 4

PlotRange->1.01

Part 5

],

Part 6

{{n,30},2,200,1},

Part 7

{pt,{-1,-1},{1,1}}

Part 8

]

Question 8

The coordinates for this picture are:

DynamicModule[{pts={{0.09200000000000008`,1.`},{-0.09199999999999997`,0.99`},{-0.22599999999999998`,0.9550000000000001`},{-0.398`,0.9000000000000001`},{-0.59`,0.81`},{-0.714`,0.7250000000000001`},{-0.8240000000000001`,0.6100000000000001`},{-0.874`,0.47`},{-0.946`,0.24`},{-0.946`,0.040000000000000036`},{-0.924`,-0.22999999999999998`},{-0.878`,-0.44499999999999995`},{-0.79`,-0.635`},{-0.6659999999999999`,-0.775`},{-0.44999999999999996`,-0.88`},{-0.22599999999999998`,-0.915`},{-0.0020000000000000018`,-0.92`},{0.42399999999999993`,-0.88`},{0.6739999999999999`,-0.765`},{0.718`,-0.685`},{0.6300000000000001`,-0.61`},{0.43799999999999994`,-0.635`},{0.242`,-0.6950000000000001`},{0.026000000000000023`,-0.72`},{-0.268`,-0.71`},{-0.506`,-0.625`},{-0.642`,-0.45499999999999996`},{-0.712`,-0.06499999999999995`},{-0.748`,0.1200000000000001`},{-0.704`,0.31499999999999995`},{-0.646`,0.4650000000000001`},{-0.522`,0.6000000000000001`},{-0.32599999999999996`,0.72`},{-0.124`,0.7850000000000001`},{0.08000000000000007`,0.81`},{0.29200000000000004`,0.8049999999999999`},{0.492`,0.7650000000000001`},{0.6280000000000001`,0.7650000000000001`},{0.6659999999999999`,0.875`},{0.5860000000000001`,0.97`},{0.44199999999999995`,0.9950000000000001`},{0.28600000000000003`,0.9950000000000001`},{0.21399999999999997`,1.`}}},Graphics[Polygon[pts],PlotRange->1]]