Docsity

MATLAB Assignment: Analyzing Weather Data for Global Warming Evidence - Prof. Joh Calandri, Assignments of Computer Science

Toggle sidebar
bg1
COMP 116
Aug 29, 2007
Assignment #2: Vectors & Matrices, due Sept 10
This assignment uses MATLAB to analyze historical weather data (1895-2006) from North Carolina,
historical weather data (1946-2006) from Antarctica, and 2006 weather data from six U.S. cities. For this
assignment, you have been provided with a ‘weather07.mat’ file that contains matrices with records of
minimum and maximum temperatures (in Fahrenheit) and precipitation (rainfall measured in inches). Such
weather data sets are typical examples of time series data.
Using this data and MATLAB, you are to perform the following:
With the historical data, ant_histannual and nc_histmonthly:
1. Plot a line graph with the average annual Antarctica temperatures for each year. Is there evidence
of global warming?
2. Plot three line graphs with the mean (average), minimum, and maximum of NC monthly
temperatures for each year. Compare the evidence for global warning with that of the plot in #1.
3. Extra Credit: Add 20 year moving averages to the three plots of question 2. For example, to the
maximum temperature plot, add a line showing the average maximum over a window from 9 years
before to 10 years after. (Note: there is a movavg function in the Financial toolbox, but it won’t
do years before and after, so you'll want to figure out your own moving average.)
4. Plot a line graph showing the NC monthly average temperature by month for each year.
With the city data, city1…city6
5. Determine which city number has the day with the greatest difference between its min and max
temperatures, and which city number has the greatest difference between its min temperature for
the year and max temperature for the year.
6. Make a bar graph showing total precipitation in 2006 for each of the six cities.
7. Plot the mean (average between max and min) daily temperature for all five cities.
8. Plot a histogram of the mean daily temperatures for city1 and city2. In which of these two cities is
the California poppy flower most likely to flourish?
9. Just for fun: The cities are Chapel Hill, NC; Los Angeles, CA; New York, NY; Phoenix, AZ;
Seattle, WA; and Fargo, ND. To which city does each data set (1 through 6) correspond?
Data
The matrix ant_histannual contains historical annual average temperatures in Celsius (C) from the
Esperanza weather station in Antarctica. Colum 1 has the year numbers and Column 2 the corresponding
temperatures. The years range from 1946-2006, with some years omitted due to insufficient data.
The matrix nc_histmonthly contains historical monthly average temperatures for North Carolina for
years 1895 – 2007 in rows. Column 1 is the year number; Columns 2 – 13 are monthly average
temperatures from Jan to Dec for each year in Farenheit (F).
Each of the six city matrices contains 4 columns with the month, maximum temperature, minimum
temperature and precipitation, respectively. Each row represents one day of observations in the year 2006.
To access this data in MATLAB, perform the following tasks:
Prepare File space
When MATLAB starts, it needs to be told where it can find and save files. In the labs, this would be on
your H: drive, and I would recommend making a folder there for this assignment. In MATLAB, type
mkdir H:\assn2, then cd H:\assn2 to tell MATLAB to read and write files in this folder. (You can use
other drive or folder names.)
Saved matrices
The data matrices are in a “.mat file” on Blackboard. To retrieve them go to Assignment >> Assn2, right
click on the file name weather07.mat and “Save Link As..” or “Save Target As..” to put it on your H: drive:
e.g., H:\assn2\weather07.mat.
IMPORTANT: use file type MATLAB MAT file or All files when you save.
Then, in your MATLAB session, use cd H:\assn2 to go the directory where you stored this file. Type load
weather07 and the matrices will be read into MATLAB. The Workspace view or the command whos can
show you the variables. Here is what I get:
pf2

Partial preview of the text

Download MATLAB Assignment: Analyzing Weather Data for Global Warming Evidence - Prof. Joh Calandri and more Assignments Computer Science in PDF only on Docsity!

COMP 116

Aug 29, 2007

Assignment #2 : Vectors & Matrices, due Sept 10

This assignment uses MATLAB to analyze historical weather data (1895-2006) from North Carolina, historical weather data (1946-2006) from Antarctica, and 2006 weather data from six U.S. cities. For this assignment, you have been provided with a ‘weather07.mat’ file that contains matrices with records of minimum and maximum temperatures (in Fahrenheit) and precipitation (rainfall measured in inches). Such weather data sets are typical examples of time series data. Using this data and MATLAB, you are to perform the following: With the historical data, ant_histannual and nc_histmonthly:

  1. Plot a line graph with the average annual Antarctica temperatures for each year. Is there evidence of global warming?
  2. Plot three line graphs with the mean (average), minimum, and maximum of NC monthly temperatures for each year. Compare the evidence for global warning with that of the plot in #1.
  3. Extra Credit: Add 20 year moving averages to the three plots of question 2. For example, to the maximum temperature plot, add a line showing the average maximum over a window from 9 years before to 10 years after. (Note: there is a movavg function in the Financial toolbox, but it won’t do years before and after, so you'll want to figure out your own moving average.)
  4. Plot a line graph showing the NC monthly average temperature by month for each year. With the city data, city1…city
  5. Determine which city number has the day with the greatest difference between its min and max temperatures, and which city number has the greatest difference between its min temperature for the year and max temperature for the year.
  6. Make a bar graph showing total precipitation in 2006 for each of the six cities.
  7. Plot the mean (average between max and min) daily temperature for all five cities.
  8. Plot a histogram of the mean daily temperatures for city1 and city2. In which of these two cities is the California poppy flower most likely to flourish?
  9. Just for fun: The cities are Chapel Hill, NC; Los Angeles, CA; New York, NY; Phoenix, AZ; Seattle, WA; and Fargo, ND. To which city does each data set (1 through 6) correspond? Data The matrix ant_histannual contains historical annual average temperatures in Celsius (C) from the Esperanza weather station in Antarctica. Colum 1 has the year numbers and Column 2 the corresponding temperatures. The years range from 1946-2006, with some years omitted due to insufficient data. The matrix nc_histmonthly contains historical monthly average temperatures for North Carolina for years 1895 – 2007 in rows. Column 1 is the year number; Columns 2 – 13 are monthly average temperatures from Jan to Dec for each year in Farenheit (F). Each of the six city matrices contains 4 columns with the month, maximum temperature, minimum temperature and precipitation, respectively. Each row represents one day of observations in the year 2006. To access this data in MATLAB, perform the following tasks: Prepare File space When MATLAB starts, it needs to be told where it can find and save files. In the labs, this would be on your H: drive, and I would recommend making a folder there for this assignment. In MATLAB, type mkdir H:\assn2 , then cd H:\assn2 to tell MATLAB to read and write files in this folder. (You can use other drive or folder names.) Saved matrices The data matrices are in a “.mat file” on Blackboard. To retrieve them go to Assignment >> Assn2, right click on the file name weather07.mat and “Save Link As..” or “Save Target As..” to put it on your H: drive: e.g., H:\assn2\weather07.mat. IMPORTANT: use file type MATLAB MAT file or All files when you save. Then, in your MATLAB session, use cd H:\assn2 to go the directory where you stored this file. Type load weather07 and the matrices will be read into MATLAB. The Workspace view or the command whos can show you the variables. Here is what I get:

load weather whos Name Size Bytes Class ant_histannual 55x2 880 double array city1 365x4 11680 double array city2 365x4 11680 double array city3 365x4 11680 double array city4 365x4 11680 double array city5 365x4 11680 double array city6 365x4 11680 double array nc_histmonthly 112x13 11648 double array You may see other variables there if you didn’t start with a new MATLAB session. MATLAB commands You’ll probably use some of the following operations: Colon (:) and end for indexing, transpose (‘), mean(), sum(),arithmetic (+,-,,/,.,./), and cumsum(). Check your book or MATLAB’s doc for more information on these. Graphing commands bar() , plot(), and hist() are the main plotting methods. All plots should have meaningful titles and axes labels, using title(), xlabel(), ylabel(), and legend(). Vectors vs. Matrices You can use indexing with colon to pull particular columns out of a matrix and operate on them as vectors: e.g., maxtemp1 = city1(:,2); would pull out the maximum temperature column. You can also use brackets [] to put columns together into new matrices, such as a matrix of maximum temperatures. You can answer these questions just with vectors, but it involves less typing to use matrices because all cities can be operated on in parallel. Remember that MATLAB operates on columns of a data matrix for plotting and summing, so transpose can come in handy. Plots Here is the essential line from the help for plot : plot(X,Y) plots the columns of Y versus X if Y is a vector. If X is omitted, uses 1..length(Y). You can select colors/markers, etc. As an example, to plot city1 maximum temperatures in red, plot(city1(:,2), ‘r’), or if you created the vector maxtemp1 above you can type plot(maxtemp1, ‘r’). For details, see doc LineSpec. Plot erases the screen unless you have said hold on. Thus, to put more than one line on the same figure, either put them as columns in a matrix and plot once, or type hold on and plot several times. Type hold off to cancel a hold, or clf to clear the figure. Please use title, xlabel, and ylabel to add titles and axes labels to each plot. When appropriate, you can use legend(’name1’, ’name2’, …) to add a legend. E.g., to plot and label the maximum temperature for the six cities, make one matrix maxtemp and: plot(maxtemp) legend('city1','city2','city3','city4','city5','city6') title('Maximum Temperature') ylabel('Temperature (F)') xlabel('Day of the Year') Hand in on Blackboard You should make a Word document in which you paste a plot, and the MATLAB commands to generate the plot, for each of the questions. (In the Figure window you can select Edit>>Copy Figure, then paste into a Word document. Edit>>Copy is not the same as Edit>> Copy Figure.) A sample can be found under Assignment, which is where you will submit your assignment by midnight Sept 10. You can also use the publish capability, added in MATLAB 7, to write html or doc files directly; more on this in class. Data sources Southeast Regional Climate Center for NC data: National Climatic Data Center for city data, and British Antarctic Survey for Esperanza Station Data