Hmwk2

advertisement
Laboratory in Oceanography - Data and Methods
Prof. Miles A. Sundermeyer
SMAST, UMass Dartmouth
MAR550, Spring 2013
Homework 2 – Due Thursday, Feb 7, 2013
1) Repeat Questions 1) & 2) from Homework 1, but this time using Matlab to do the computations. To
do this, create a ‘.m’ file that assigns the arrays, A, B, k, and p, and do the computations line by line, e.g.,
% For computing solutions to Homework 1, linear algebra review
%
% Written by Miles A. Sundermeyer, 2/4/09
% Question 1
A = [2 4 6]'
B = [-2 7 5]'
k=3
p=5
% a) find A + B
A+B
.
.
.
etc.
Note: Please follow the ‘best programming practices’ pointers from last week’s lecture as appropriate. Also,
please submit a hard copy of your .m file as well as an electronic version to me as part of your solution.
2) On the course website: http://www.smast.umassd.edu/mixing/course_LabInOcean.html you will find a
data file named ‘drifter.dat’ containing ascii drifter data collected during a 1 day deployment off the coast of
North Carolina. The following data for each of 4 drifters are in successive columns of the data file:
yearday
hr
min
lat_deg
lat_min
lon_deg
lon_min
Thus there are 4 drifters x 7 columns = 28 columns, with each row consisting of successive data records for
each drifter. Load the data file into matlab (‘load drifter.dat’) and perform the following manipulations and
analyses. Note, in terms of what you hand in for this assignment, please print your Matlab code (.m file) and
the appropriate Matlab figures. To print a Matlab figure to a postscript file, use ‘print –depsc2 <fnm>’ to
print the active figure to a file. To print to a jpeg file, use ‘print –djpeg <fnm>’. Please submit hard copies of
your .m file and figures, as well as an electronic version of your .m file separately by email.
a. Separate the drifter data into 4 distinct drifter arrays, each containing 7 columns and the requisite
number of rows.
b. For each drifter array, find the row indices containing no data (i.e., rows with nan’s), and eliminate
these rows from the individual drifter arrays using [ ] assignments.
c. Use the lat_deg and lat_min arrays to make decimal latitude and longitude arrays for each drifter.
d. Plot the (lon, lat) positions on a single plot using the ‘plot’ command (note: please use different colors
for each drifter for clarity, also be sure to label your axes).
1
Laboratory in Oceanography - Data and Methods
Prof. Miles A. Sundermeyer
SMAST, UMass Dartmouth
MAR550, Spring 2013
e. Create a single monotonically increasing yearday array from the time variables day, hr, min. For this,
use your understanding of matrix algebra to do this in a single matrix computation for each drifter.
(Hint: [n x 3][3 x 1] = [n x 1]).
f.
Plot time series of the float lons and lats on a new figure (use ‘figure(2)’ to create a 2nd figure
window, etc.; again use color for clarity and label axes).
g. Use the ‘diff’ command to compute east/west and north/south float velocities (u = x/t, v = y/t).
Assume here that 1 deg lat = 111 km, 1 deg lon = 111*cos(Lat), with Lat = pi/180*33.8 degrees.
h. Plot the time series of float velocities, u and v, on a new figure (again use color for clarity and label
axes, also note that the diff calculation will give you an array that is 1 element shorter than the
original – therefore, to plot velocity as a function of time, use (1:end-1) to index your time array when
plotting against velocity).
2
Download