SUNY Geneseo Department of Mathematics

Lab 3—Plotting

Math 230 01
Fall 2015
Prof. Doug Baldwin

Complete by Wednesday, October 7
Grade by Friday, October 9

Purpose

This lesson establishes a basic ability to draw graphs with Matlab. It also introduces parametric equations as an important mathematical idea with applications for generating a wide variety of interesting curves.

Background

Our textbook introduces 2-dimensional plotting in sections 6.3 and 6.4, and we will talk about this material in class on October 2. The Edinburgh video lecture on “ Creating a Simple Plot” covers similar material, with a nice summary of how to do some of it interactively. The video lecture on “ Writing a Simple Script” is also relevant—even though it is mainly about writing scripts, the example it uses is a script that plots a circle.

The concept of a “parametric curve” or set of “parametric equations” is central to graphing in Matlab, and to lots of other computer graphics. You can find an introduction to (or review of, if you’ve seen them before) parametric equations in the “Parametric Curves—Basic Graphing” video at https://www.youtube.com/watch?v=tsnHL1Lb5MU.

Activity

Write Matlab scripts or functions, as directed, to solve each of the following problems.

Problem 1—Circles and Friends

The parametric equations

x(t) = cost
y(t) = sint

generate a circle when plotted with t ranging from 0 to 2π. Write a Matlab script that plots this circle. It will be most obviously circular if your plot has square axes—i.e., 1 unit on the x axis is the same length on screen as 1 unit on the y axis.

What determines the radius of the circle generated by these equations? Test your ideas by extending your script (by adding a second “%%” section to it) to plot two concentric circles with different radii. (For a bit of extra challenge, use different colors, line widths or styles, etc. for each circle.)

Finally, think about how you would plot an ellipse (hint: the ellipse’s axes can be parallel to the x and y axes). Try your ideas by extending your circle script (with a third section) to plot one or more ellipses. Be sure that your ellipse (or ellipses) looks elliptical when plotted with square axes, i.e., that the elliptical appearance isn’t just due to non-uniform axes.

Problem 2—Spirals

Try to devise parametric equations that describe each of the following kinds of spiral:

  1. Spirals in which each turn of the spiral is wider than the previous one by a constant additive amount. In other words, if the ith turn of the spiral ends with radius r, the (i+1)th turn should end with radius r + a for some constant a. Such spirals are called “Archimedean” spirals
  2. Spirals in which each turn is wider than the previous one by a constant multiplicative factor. In other words, if the ith turn of the spiral ends with radius r, the (i+1)th turn should end with radius ar for some constant a. These spirals are called “logarithmic” spirals.

Once you think you have equations for the two kinds of spiral, write two Matlab functions based on your equations—one function should draw an Archimedean spiral and the other should draw a logarithmic spiral. Both functions should at least take the constant a as an argument, and may take other arguments as you wish (e.g., to specify the number of turns of the spiral to draw, its color, its line width, etc.) Note that neither function has a result variable though. Test the functions to see if they draw the expected sorts of spiral (if not, is the problem in your equations, or in your code? how would you know?) Put some thought into selecting values of a and the number of turns to draw for both spirals so that you can be reasonably certain that your code and equations are correct.

Extra—“Spirograph” Figures

The Spirograph (legally a trademark of Hasbro) toy produces very elaborate curves that are technically known as hypotrochoids and epitrochoids. Not surprisingly, these curves can also be described by parametric equations. The Wikipedia article on Spirographs has a good treatment of the mathematics of the Spirograph that derives these equations. Use them to write a Matlab function that simulates a Spirograph. Your function will need arguments for the radii of the two wheels and the distance of the simulated pen point from the center of the inner wheel.

Follow-Up

I will grade this exercise in a face-to-face meeting with you. During this meeting I will look at your solution, ask you any questions I have about it, answer questions you have, etc. Please bring a written solution to the exercise to your meeting, as that will speed the process along.

Sign up for a meeting via Google calendar. If you worked in a group on this exercise, the whole group should schedule a single meeting with me. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.