GOAL: Compute and plot p(z) for an atmosphere where T = T(z), using more advanced Matlab function techniques.
1. As with Lab 3, follow the instructions for accessing meteorology computers to log into your Meteorology account. If you are sharing a computer, the second student should open a second window, as per the instructions, and then login as her/himself, entering in the second window,
ssh LOGNAME@0
where the student's login name should be substituted for LOGNAME. Then take turns completing the rest of the lab.
2.
First, we want to create a new function file, height.m, that will give
us a vector of heights z. The function will be given the
number of vector elements, N, and the spacing between height levels,
Dz. Our formula will be
z(i) = i * Dz , (5.2.1)where Dz is in [meters] and z(i) is the ith element of the vector.
function [z]=height(N,Dz) % Assume z starts at z = 0 % Then loop N times to get an array of % z values extending upward from the % surface with spacing Dz for i = 1 : N % Note semi-colon (;) at end of line. This tells % Matlab NOT to echo its computation back to the % screen. z(i)=(i-1)*Dz ; % End loop end
3.
Next, we want to create a new function file, temperature.m, that will give
us a vector of temperatures vs. height. We will assume constant lapse
rate, gamma. Our formula will be
T(i) = Ts + z(i)*gamma , (5.3.1)where gamma is in [deg/m] and Ts is surface temperature..
function [T]=temperature(Ts,gamma,z) % Compute T(z) given the surface temperature Ts % and the lapse rate gamma. T = Ts - gamma*z ;
4.
Now let's go into Matlab to see how these functions work for us.
Start matlab:
matlab
If you are logged into Project Vincent, but not on the meteorology computers,
then you have to take some extra steps to start Matlab. Enter
add matlab
add math
matlab
Do these "adds" ONLY if you are logged into Project Vincent using
non-meteorology computers!
A window with a fancy 3-d graph may appear and then disappear. Then you may see a symbol like an upside-down "L" appear at your mouse pointer on the screen. Click your mouse button, and a window with 3 panels will open.
You may need to move the window to center it. This can be done by holding down the mouse button when the mouse pointer is on the upper bar of the window and dragging the window to where you want it.
5.
First make sure that Matlab is working in your home directory (where
presumably all your Matlab files are located):
>>cd ~
Assign an array of z(i), using a relatively coarse spacing of 1000 m
(1 km):
>>N=11
>>Dz=1000
>>z=height(N,Dz)
Answer these questions:
6.
Now assign z(i) using a much finer spacing:
>>N=51
>>Dz=200
>>z=height(N,Dz)
We will use this finer resolution for integrating numerically the
hydrostatic equation.
7.
Now that z is assigned values, test our function temperature.m
-3 3.0e-3 = 3.0 x 10Note also that Ts2 and gamma1 are approximately the global-average values of surface temperature and lapse rate, respectively.
8.
Now that we have z and T(z), we are ready to compute p(z).
We will compute p(z) by integrating the hydrostatic equation up from
the surface. If we have
dp -- = -g*rho dz then dp = -g*rho*dz = -g*p*dz/(Rd*Tv) or d(lnp) = -g*dz/(Rd*Tv)
This formula can be used to tell us how log(p) changes over an interval dz. We will assume here that for the virtual temperature, Tv ~ T, and that g = g0 = 9.8 m/s**2.
I have written a function file to do this integration. You should copy it to your home directory:
That last character in the line is the tilde, ~. Note that there is a blank space before it. The "~" refers to your home directory. No matter where you are in the file space, you can always copy files back to your home directory by telling the computer to copy to "~".
9.
Take a look at pressure_2.m
emacs pressure_2.m
Answer these questions
10.
Now restart Matlab.
Now enter (note the finer grid spacing)
>>N=51
>>Dz=200
>>Ts1=250
>>Ts2=288
>>gamma1=6.5e-3
>>gamma2=9.8e-3
>>z=height(N,Dz)
>>TEM1=temperature(Ts1,gamma1,z)
>>TEM2=temperature(Ts1,gamma2,z)
>>TEM3=temperature(Ts2,gamma1,z)
Then compute p(z) profiles using the function pressure_2.m:
>>PR1=pressure_2(N,Dz,TEM1)
>>PR2=pressure_2(N,Dz,TEM2)
>>PR3=pressure_2(N,Dz,TEM3)
Plot the p(z) profiles you just created:
>>plot(PR1,z,'y-',PR2,z,'c--',PR3,z,'y-.')
Answer these questions
EXTRA CREDIT: As in Lab 3, use "help" to learn how to put on your plot axis labels, a title, and text labels for each curve. Then add any or all of these to the plot.
Finally, whether or not you do the extra credit, save the current plot by "printing" it to a file called
pressure_2.ps:
>>print -dps pressure_2.ps
As in Lab 3, this will create a file called pressure.ps in the
directory you are working in. (The file is in so-called postscript
format.) Following instructions given in
Lab 3, step 14., print a copy of your plot..
11.
Finally, compare your p(z) when T=T(z) with the p(z) computed for an
isothermal temperature field, using the pressure.m file you created in
Lab 3:
>>PR4=pressure(z,Ts2)
>>plot(PR3,z,'y-',PR4,z,'c--')
Here, we are assuming that geopotential height Z = distance above the
surface z, a good approximation for the troposphere.
Answer these questions
As in step 10., print a copy of the plot, this time to a file called "pressure_3.ps". You will again get extra credit for labeling it.
Return to Meteorology 301 Lab List
Return to Meteorology 301 Homepage