Learning Mathematica Basics—Graphics II

Solve each of the following problems using Mathematica exclusively.

1.  A function is defined parametrically if both x and y are defined as functions of a third, independent, variable, usually represented by t.  This type of definition can be extremely useful when dealing with relations such as circles, ellipses, spirals, etc.  i.e. objects which fail the usual vertical line test of an ordinary function.

Mathematica allows the plotting of parametrically defined functions by using the the command ParametricPlot.  Ask for its syntax.

2.  The first form looks simple enough.  Lets plot a circle!  One way to do this would be to remember the trigonometry of the unit circle, and realize that the (x,y) pairs around it are all given by (sin t, cos t) with 0≤t≤2π.  The plotting command would be:

                ParametricPlot[{Cos[t],Sin[t]},{t,0,2Pi}]

3.   That looks more like an ellipse than a circle!  The reason for this problem is Mathematica's default AspectRatio, i.e. the ratio of the height of the plotting window to its width.  You may recall in the last quiz looking at the list of Options available for the Plot command.  One of these was AspectRatio, and it's default value is 1/GoldenRatio, which is approximately 1/1.6.  In order to render the previous graph truly  circular we want Mathematica to make the vertical and horizontal scales of the graph equal.  To achieve this we would insert the option  ,AspectRatio->Automatic   before the last bracket of the command above.  Go ahead and redo the command below.

4.   Hopefully you have now produced a circular circle.  Now it's your turn to do a few parametrically defined graphs.  In each case below attempt to visualize what the curve is going to look like before you make Mathematica do the work.  This is good for your mathematical reasoning.

a)   Plot the curve (3 cos t, 3 sin t) on the interval 0≤t≤2π.

b)   Plot the curve (2 cos t, 5 sin t) on the interval 0≤t≤2π.

c)   Plot the curve ((t + 1) cos t, (t + 1) sin t) on the interval 0≤t≤2π.

d)   Plot the curve (sin t cos t, sin t) on the interval 0≤t≤2π.

5.   As you saw above, ParametricPlot is the key to plotting graphs of non-functions.

Now you may recall from either trogonometry or your calculus class the concept of a non-Cartesian coordinate system referred to as polar coordinates.  In this system the location of a point in the plane was not given by an (x, y) pair, but rather by an ordered pair of the form (r, t), where r represents the distance of the point from the origin, and t is the angle that the line segment joining the point to the origin makes with the positive x-axis.  The conversion formulas to move from polar to cartesian coordates are x = r cos t, and y = r sin t.  Mathematica does not have a command for making PolarPlots built in.  In fact try asking about PolarPlot by issuing the command ?PolarPlot.

6.   So, in order to plot a polar graph we would have to utilize the two conversion formulas ourselves in concert with the ParametricPlot command.  However, maybe someone else has already done the work for us!

Remember, Mathematica is an extensible system.  New commands can be added to Mathematica's basic set by loading in what are referred to as packages.  A package is a set of new commands that someone decided to create because they found that they needed to use them a lot.  This can often happen in research or a job environment.

Someone has already created a package that enables Mathematica to do PolarPlots.  All we need to do is load the package.  The one we want is called Graphics`Graphics`.  (The symbol used here is the gràve accent—it's usually on the same key as the tilde " ~ " on your keyboard.)  In order to load the desired package issue the command:  <<Graphics`Graphics`

7.   No visible effect from issuing the above command!  Let's investigate further!  Re-issue the command you gave in problem 5:  ?PolarPlot.

8.   Woah!  That one didn't work back in problem 5, but it does now!  That's because the package we just loaded contained (among other things) the definition of a brand new command—PolarPlot.  Apparently the person who created it was even nice enough to include the help-text shown in problem 7.

Well let's give PolarPlot a try!  The equation for a cardioid (or one such example, atleast) is r = 1 + cos t.  Reading the description in problem 8 it looks like the appropriate command would be:  PolarPlot[1+Cos[t],{t,0,2Pi}].  Go ahead and try it.

9.   Hopefully you got the appropriate "heart" shape.  Notice that the maker of the Graphics`Graphics` package did us another favor.  The PolarPlot command automatically uses an AspectRatio of Automatic.  This is because polar-coordinate graphs are based on circular measure—they'd look a little silly with the usual AspectRatio.

Anyway, let's use the PolarPlot command a few more times.  A typical type of polar graph is the "rose."  Roses have the form r = cos(a t) where a is an integer.  Try plotting the rose when a = 3.

10.   Apparently the value of a dictates the number of leaves (or petals, take your pick) of the rose.  Produce a rose with 7 petals.

11.   Now try doing problem 9 again, but use sine instead of cosine.

12.   Compare problem 9's graph with problem 11's.  Notice what difference the use of a sine instead of a cosine made—just a rotation.  Think about why the difference occurs!

OK, let's live dangerously!  The definition of a rose said that a must be an integer.  How about if we defy the Nazi dictators who claim we must let a be an integer, and use a decimal instead?  Try making a cosine rose with a = 2.5.

13.   Hmmm!  Looks like it was going to get interesting, but it didn't get chance to finish.  Perhaps if we let t go further than 2π it might get the full cycle done.  How much further?  Well since we're dealing with halves, how about doubling the usual interval and going up to 4π?  Try it!  Redo the last problem with this longer t interval.

14.  That's more like it!  Let's now do some art!  

First we'll produce a list of roses like the one above, but with varying radii.  The radius of a rose is controlled by simply multiplying the cosine by the radius you want—i.e. so far all of our roses have had radius 1.  We'll use the Table command to do this for us, and make radii ranging from 0.1 up to 1 in steps of 0.1.  We'll store the list in the variable roselist.  The command would be:

                roselist=Table[k Cos[2.5 t],{k,.1,1,.1}]
 
Go ahead and issue it.

15.   Now we'll probably want to put some color into our "art" so let's build ourselves a list of colors to use in the picture.  Issue the command:

                       huelist=Table[Hue[k],{k,0,.9,.1}]

16.   Time to put it all together!  Issue the command:

PolarPlot[Evaluate[roselist],{t,0,4Pi},PlotStyle->huelist]

17.  That should have produced a very pretty picture!  Now it's time for you to do one on your own.  Make a piece of "polar art" by using some of the same techniques as we did to produce the graph above, but don't do roses.  Do something different!  Experiment!