Quiz #1 (The Butterfly Curve) -- Fall 2007

Contents

First attempt on [0, 2pi]

Our first attempt will plot the parametric equations on the domain [0,2pi]. We use 200 equally spaced points from the domain.

Close all open figure windows.

The following command will close all open figure windows. This is something we do so that running the file will popup a fresh new figure window and we won't have to use the mouse or the command shg to bring the figure window to the front of the desktop.

close all

The domain.

We use the linspace command to produce 200 equally spaced points on the domain [0,2 pi].

t=linspace(0,2*pi,200);

Compute x and y.

We next compute x and y. Note the use of the array operators (dot-notation).

x=sin(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);
y=cos(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);

The plot.

We plot the result in the xy-plane

plot(x,y)

Annotate the axes

We use the xlabel and ylabel commands to annotate the axes.

xlabel('x-axis')
ylabel('y-axis')

Title

The parametric equations are too long to fit in a one-line title. Hence, we will create a cell array that holds each equation as a row. The title command then takes the cell array and typesets it as a multi-line title.

Note the use of braces in titleStr(1) = { }.

There's a bit of TeX code here. The caret is used for superscripts in TeX. If you wish more than one character to be in the superscript, use braces to surround the intended superscript.

titleStr(1) = {'x = sin(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
titleStr(2) = {'x = cos(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
title(titleStr)

Increasing the domain.

After some exploration, we increased the domain to [0,12pi]. As you can see the graph becomes quite 'jagged.'

t=linspace(0,12*pi,200);

x=sin(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);
y=cos(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);

plot(x,y)

xlabel('x-axis')
ylabel('y-axis')

titleStr(1) = {'x = sin(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
titleStr(2) = {'x = cos(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
title(titleStr)

Smoothing the plot

The next step is to increase the number of plotted points to remove the 'jagged' appearance of the plot.

t=linspace(0,12*pi,10000);

x=sin(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);
y=cos(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);

plot(x,y)

xlabel('x-axis')
ylabel('y-axis')

titleStr(1) = {'x = sin(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
titleStr(2) = {'x = cos(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
title(titleStr)

Increasing the domain I

Note that increasing the domain adds further detail.

t=linspace(0,20*pi,10000);

x=sin(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);
y=cos(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);

plot(x,y)

xlabel('x-axis')
ylabel('y-axis')

titleStr(1) = {'x = sin(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
titleStr(2) = {'x = cos(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
title(titleStr)

Increasing the domain II

Note that increasing the domain adds further detail.

t=linspace(0,40*pi,50000);

x=sin(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);
y=cos(t) .* (exp(cos(t)) - 2 * cos(4*t) + sin(t/12).^5);

plot(x,y)

xlabel('x-axis')
ylabel('y-axis')

titleStr(1) = {'x = sin(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
titleStr(2) = {'x = cos(t) (e^{cos(t)} - 2 cos(4t) + sin^2(t/12))'};
title(titleStr)

Open question

Will the butterfly curve ever close? That is, does it have a chance of being periodic? Or will increasing the domain always reveal detail that we didn't see with previous domains?