Presentation is loading. Please wait.

Presentation is loading. Please wait.

Examining Divergence and Vorticity in the Gulf Stream

Similar presentations


Presentation on theme: "Examining Divergence and Vorticity in the Gulf Stream"— Presentation transcript:

1 Examining Divergence and Vorticity in the Gulf Stream
SO335 MATLAB LESSON Examining Divergence and Vorticity in the Gulf Stream using INDICES, FINITE DIFFERENCING, AND LOOPS 19 September 2017

2 dx & dy lat2 lon1 lon2 lat1 y2 x1 x2 y1 This page:
Longitude changes from WestEast. This corresponds to which distance variable? x y z (Circle one) Change in this direction will be evaluated as: dx dy dz (Circle one) Identify the row/column assoc. with the points of interest: lat = 39N, row _____ lon = 291E, column____ Assume that there are 111 km/degree (lat & lon) Calculate dx at 39N, 291E (give answers in degrees AND in km AND in m). Think: why this is important? To code this, we need to tell MATLAB which row(s) and column(s) to use in the calculation. The format for the command is shown below. Re-write it and fill in the correct row and column numbers for lon2 and lon1. {Hint 1: your row numbers should be between and your column numbers should be between Hint 2: multiply by 111 now to do ensure your answer is in meters.} Plug this equation into Matlab to check your math. {Hint: Make sure you enter a value for the blue text.} Latitude changes from SouthNorth. This corresponds to which distance variable? x y z (Circle one) Change in this direction will be evaluated as: dx dy dz (Circle one) Identify the row/column assoc. with the points of interest: lat = 39N, row _____ lon = 291E, column____ Assume that there are 111 km/degree (lat & lon) Calculate dy at 39N, 291E (give answers in degrees AND in km AND in m). Think: why this is important? To code this, we need to tell MATLAB which row(s) and column(s) to use in the calculation. The format for the command is shown below. Re-write it and fill in the correct row and column numbers for lat2 and lat1. {Hint 1: your row numbers should be between and your column numbers should be between Hint 2: multiply by 111,000 now to do ensure your answer is in meters.} Plug this equation into Matlab to check your math. {Hint: Make sure you enter a value for the blue text.} This page: dx & dy

3 du & dv This page: u2y2 u1x1 u2x2 u1y1 v2y2 v1x1 v2x2 v1y1
Note that du can be calculated in two different directions – by row or by column. To calculate du/dx, we need to choose u2 & u1 that correspond to x2 & x1. Calculate du(fordx) at 39N,291E: To calculate du/dy, we need to choose u2 & u1 that correspond to y2 & y1. Calculate du(fordy) at 39N,291E: To code these into Matlab, we need to identify the rows and columns for the differencing: dufordx=u(124,815)-u(124,813) dufordy=u(123,814)-u(125,814) Plug these equations into Matlab to check your math Like du, dv also can be calculated in two different directions – by row or by column. To calculate dv/dx, we need to choose v2 & v1 that correspond to x2 & x1. Calculate dv(fordx) at 39N291E: To calculate dv/dy, we need to choose v2 & v1 that correspond to y2 & y1. Calculate dv(fordy) at 39N,291E: To code these into Matlab, we need to identify the rows and columns for the differencing: dvfordx=v(124,815)-v(124,813) dvfordy=v(123,814)-v(125,814) Plug these equations into Matlab to check your math This page: du & dv

4 Based on your math, should the flow be:
Use the values in the tables at right to draw the velocity vectors at and adjacent to our point of interest (i.e. in the 5 shaded boxes at right). (HINT: draw u, then v, then then .) Using values for du, dv, dx, and dy at 39N, 291E from the past two pages, calculate: Based on your math, should the flow be: Convergent or divergent? Cyclonic or anticyclonic? Check these against your wind vectors at right. Does your math match the physical flow represented in the vectors? This page: Draw vectors, calc div & rel vort, describe the flow, & think

5 Matlab: Using Indices in Calculations
The MATLAB commands for the past calculations are summarized here: dx=(cur_lon(124,815)-cur_lon(124,813)).*111000; dy=(cur_lat(123,814)-cur_lat(125,814)).*111000; dufordx=u(124,815)-u(124,813); dufordy=u(123,814)-u(125,814); dvfordx=v(124,815)-v(124,813); dvfordy=v(123,814)-v(125,814); Using the terminology above (i.e. the variable names on the left side of the equal sign), write out the commands you would type into MATLAB to calculate divergence and relative vorticity at 39N, 291E: Obviously, specifying every cell for these operations would be exceptionally time intensive. To program efficiently, we will set up a loop to calculate these variables at every point in our domain. First, use the (row, column) location of our point of interest (39N, 291E) to define the indices we’ll use: i = row = __________ j = column = ________ Then, rewrite the MATLAB commands listed above in terms of i and j. NOTE: Since we are calculating values for many locations, and we want to save the value at each location, we have to assign each value we calculate into a particular row (i) and column (j). Complete the right column below. dx(i,j)=(cur_lon(i,j+1)-cur_lon(i,j-1)).*111000; dy(i,j)=(cur_lat(( , )-cur_lat( , )).*111000; dufordx(i,j)=u(i,j+1)-u(i,j-1) ; dufordy(i,j)=u( , )-u( , ); dvfordx(i,j)=v(i,j+1)-v(i,j-1); dvfordy(i,j)=v( , )-v( , ); Check the accuracy of the commands above, by verifying them in MATLAB. First define values for i & j: i=124; j=814; Then, type the equations into MATLAB. Verify that your answers (using the equations with i’s and j’s) match the answers given from the equations without i’s and j’s.

6 Matlab: Constructing a “For” Loop, part 1
The MATLAB commands for the past calculations are summarized here: dx(i,j)=(cur_lon(i,j+1)-cur_lon(i,j-1)).*111000; dy(i,j)=(cur_lat(i-1,j)-cur_lat(i+1,j)).*111000; dufordx(i,j)=u(i,j+1)-u(i,j-1); dufordy(i,j)=u(i-1,j)-u(i+1,j); dvfordx(i,j)=v(i,j+1)-v(i,j-1); dvfordy(i,j)=v(i-1,j)-v(i+1,j); The cool thing at this point is that we can calculate the variables above (dx, dufordx, dvfordx, dy, dufordy, dvfordy) as well as divergence and vorticity, at many points using the exact syntax above. Our North Atlantic domain spans 5-72N, E. We will use a smaller subsection of this region, from 20-45N, E. Which indices correspond to these lats and lons? lat 20N = row_____ lat 45N = row_____ lon 275E = column _____ lon 310E = column _____ EXAMPLE 1: Using the template shown at left, construct a “for” loop to calculate the 6 variables above for latitude 39N and longitudes E. HINT: Set the value for “i” before the loop. Since this will be the value of the latitude (rather than a reference to a (row, column), we call it “hard coding”; so we would say “hard code the latitude in before the loop”.) i = 39 for j = startindex:stopindex % remember “j” corresponds to longitudes, which vary by column (so this is a range of columns) Command 1 Command 2 Command 3 Command 4 Command 5 Command 6 end

7 Matlab: Constructing a “For” Loop, part 2
Reminder: our subsection of the North Atlantic domain spans 20-45N, E, which corresponds to: lat 20N = row_____ lat 45N = row_____ lon 275E = column _____ lon 310E = column _____ EXAMPLE 2: Construct a nested “for” loop to calculate the 6 variables above for latitudes 20-45N and longitudes E. HINT: Specify the latitude range for “i” and the longitude range for “j”. for i=startindex:stopindex % remember “i” corresponds to latitudes, which vary by row (so this is a range of rows) for j = startindex:stopindex % remember “j” corresponds to longitudes, which vary by column (so this is a range of columns) Command 1 Command 2 Command 3 Command 4 Command 5 Command 6 end Now you have all of the variables necessary to code the calculations of divergence and vorticity: Divergence = (dufordx./dx) + (dvfordy./dy) ; RelVorticity=(dvfordx./dx) - (dufordy./dy); What are the units for divergence and vorticity? What would have happened if we would have left “dx” and “dy” in degrees instead of converting them to meters? Check your work by creating filled contour plots of divergence and relative vorticity. Coding hints are here: [c,h]=contourf(cur_lon(106:181,766:871),cur_lat(106:181,766:871),CurrentMag(106:181,766:871)); [c,h]=contourf(cur_lon(106:181,766:871),cur_lat(106:181,766:871),RelVorticity(106:181,766:871)); k=quiver(cur_lon(106:181,766:871),cur_lat(106:181,766:871),u(106:181,766:871),v(106:181,766:871),2,'w'); set(k,'LineWidth',2) line(coastline(:,1),coastline(:,2),'color','k','linewidth',1) %This plots the coastline for the world. Constrain the axes with xlim and ylim. xlim([ ]) ylim([20 45]) Note: you will need several other commands to create the figures properly.


Download ppt "Examining Divergence and Vorticity in the Gulf Stream"

Similar presentations


Ads by Google