Computer Science 1060
Scientific Programming
Assignment 03 - Plotting Data

Contents:


Overview

Topic: Plotting Data
Related Reading: Ch. 5 as well as coverage from lecture.

For each of the following problems, your goal is to create a script that precisely replicates the figure that we demonstrate. Please make sure to pay attention to issues like axis bounds, labels, titles, legends, and other such aesthetics. You should be submitting four separate fies: arch.m, sunflower.m, population.m, and stock.m.

Submit your m-files via web form here.


Problems to be Submitted (20 points)

Problem A)
(5 points)
The Gateway Arch is shaped according to the equation:

\begin{displaymath}y = 757.7 - 127.7 \cosh\left(\frac{x}{127.7}\right) ft.\end{displaymath}

for x ranging from -330 to 330 and using MATLAB's hyperbolic cosine function (cosh). Create a script arch.m that produces a figure of the arch matching the following style. Note that there is a grid in the background and that the aspect ratio of the graph is square.

Problem B)
(5 points)
Consider the following rendition of the seeds in a sunflower.

We used the following mathematical model to produce this image. We fix a constant $d = 137.51$ and have $n$ ``seeds'' numbered from 1 to 1000. Seed $s_k$ is plotted at a location

\begin{eqnarray*}
x_k & = & r_k \cdot sin(\theta_k)\\
y_k & = & r_k \cdot cos(\theta_k)
\end{eqnarray*}

where $r_k = \sqrt{k}$ and $\theta_k = \frac{\pi \cdot d}{180} k$.

Create a script sunflower.m that produces such a figure (note well that displayed axes are intentionally omitted from the figure, and that the image aspect ratio is square).

For your own amusement you might see what kind of patterns you get by slightly modifying the value of $d$, but submit the version with the prescribed value.

Problem C)
(5 points)

Population growth can often be modeled with the following function:

\begin{displaymath}population = \frac{a}{b + e^{ct}}\end{displaymath}

where $a$, $b$, and $c$ are well-chosen constants, and $t$ measures time. For example, a reasonable model for the population of the United States over time uses the values a = 1.313e-18, b = 4.667e-27 and c = -0.03134, with $t$ measured in years.

For this problem, we want you to graph the population estimate when compared to the actual data for the U.S. population for the period from 1650 up to 2000. We are providing a text file with the actual raw data (statistics taken from wikipedia). Our file has a simple format, starting as

1650        50400
1670       111900
1690       210400
1700       250900
You may download the file population.txt to save in your working directory. It can be loaded from within a MATLAB script with a command such as
pop = load('population.txt');
in which case the variable pop will be set to an array with n rows and 2 columns.

Write a script population.m that reproduces the following figure, with the blue dots being the actual data read from the file and the red line being the estimating function (you can plot the blue dots in MATLAB by using a line specification of 'b.').

Problem D)
(5 points)

Many financial web sites will display charts similar to the one shown below showing the price of the Dow Jones Industrial Average as well as the overall market volume for each day of the most recent year (figure courtesy of Yahoo Finance).

Yahoo also shares its raw data, not just for the year but for its full history. For this assignment, we have downloaded the raw data for the Dow Jones going back to 1928. Our goal is to use MATLAB to reproduce a similar view of the above timeframe.

We are providing the raw data in a text file (download here), wih one row for each day of market activity. It is arranged in columns that designate

Year Month Day Daily Opening Price Daily High Price Daily Low Price Daily Closing Price Daily Volume
1928 10 01 239.43 242.46 238.24 240.01 3500000
1928 10 02 240.01 241.54 235.42 238.14 3850000
 ...
2009 01 29 8373.06 8373.06 8092.14 8149.01 5067060000
2009 01 30 8149.01 8243.95 7924.88 8000.86 5350580000

Your goal:
You should create a script stocks.m that generates a figure mimicking the one shown above, as best possible (I do not expect you to be able to match all of the aestetics for this one). The following advice will help you.


Extra Credit (2 points)

Problem E)

Extra credit about stock market graph with high/low error bars. Produce a graph analogous to the one below, based on use of the errorbar command and the daily open/high/low/close values. The errorbar command is capable of producing the vertical boxes denoting the high and low prices for the market that day. The three-argument version of the errorbar command in particular allows you to specify a central x and y coordinate for each box, as well as the height of the box. The stems to the left and right of the boxes denote the open and closing prices, respectively, and will need to be plotted separately. There are multiple ways to achieve this, but I would suggest using the left and right arrow data labels with the regular plot command.



(figure courtesy of marketwatch.com)


Originally by
Michael Goldwasser