SUNY Geneseo Department of Mathematics

Lab 3—Plotting

Math 230 02
Spring 2016
Prof. Doug Baldwin

Complete by Monday, February 22
Grade by Thursday, February 25

Purpose

This exercise 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. In particular, I expect you to finish this lab able to (1) write parametric equations for such circle-like shapes as circles, ellipses, and spirals, (2) evaluate parametric equations into vectors of values in Matlab, and (3) plot parametric equations in Matlab.

Background

Our textbook introduces 2-dimensional plotting in sections 6.1 and 6.2, and we will talk about this material in class on February 17.

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 your solution on your computer, as that will speed the process along.

Sign up for a meeting via Google calendar. Please make the meeting 15 minutes long, and schedule it to finish before the end of the “Grade By” date above.