Plot contour using matlab and octave
(example: geostrophic vorticity and vorticity advection)
% Constants
Lx = 6000.e3; % wave length in X (6000 km) Ly = 4000.e3; % wave length in Y (4000 km) k = 2*pi/Lx; % zonal wavenumber [1/m]
l = 2*pi/Ly; % meridional wavenumber [1/m]
...
Define constants
% Define domain size
x1 = (-3000:100:3000)*1.e3; % set domain in x [m]
y1 = (-1000:100:1000)*1.e3; % in y [m]
[x,y] = meshgrid(x1,y1); % make 2D matrix
Set domain
Same as previous lecture
% compute variables (monochromatic wave) phi = 55000 - U*f0*(y);
phi = 55000 - U*f0*(y);
phi = phi + amp*sin(k*x).*cos(l*y);
Ug = U + amp*l*sin(k*x).*sin(l*y)/f0;
Vg = amp*k*cos(k*x).*cos(l*y)/f0;
vor = -amp*(k^2+l^2)* sin(k*x).*cos(l*y)/f0;
vor_x = -amp*(k^2+l^2)*k*cos(k*x).*cos(l*y)/f0;
vor_y = amp*(k^2+l^2)*l*sin(k*x).*sin(l*y)/f0;
vor_adv = -Ug.*vor_x -Vg.*(vor_y+b0);
Compute values
Source: http://folk.ntnu.no/leifh/teaching/tkt4140
Laplacian ( ∇2Φ = Φ
xx + Φ
yy)
Source: http://folk.ntnu.no/leifh/teaching/tkt4140
Laplacian ( ∇2Φ = Φ
xx + Φ
yy)
Source: http://folk.ntnu.no/leifh/teaching/tkt4140
Laplacian ( ∇2Φ = Φ
xx + Φ
yy)
Source: http://folk.ntnu.no/leifh/teaching/tkt4140
Laplacian ( ∇2Φ = Φ
xx + Φ
yy)
% compute variables (monochromatic wave) phi = 55000 - U*f0*(y);
phi = 55000 - U*f0*(y);
phi = phi + amp*sin(k*x).*cos(l*y);
Ug = U + amp*l*sin(k*x).*sin(l*y)/f0;
Vg = amp*k*cos(k*x).*cos(l*y)/f0;
% If you like numerical methods --- dx = 100.e3; dy = 100.e3;
Vor = 4*del2(phi, dx, dy)/f0;
[vor_x, vor_y] = gradient(vor, dx, dy) vor_adv = -Ug.*vor_x -Vg.*(vor_y+b0);
Compute values
% Figure2: plot Geopotential and vorticity figure(2)
subplot(2,1,1) % geopotential
[cs,h]=contour(x/1000,y/1000,phi,'linewidth',4);
clabel(cs,h,'LabelSpacing’,400) axis([-3000,3000,-1000,1000]))
xlabel('x (km)’); ylabel('y (km)') title('Geopotential (m^2/s^2)')
Plot contour
% Figure2: plot Geopotential and vorticity figure(2)
subplot(2,1,1) % geopotential ...
subplot(2,1,2) % vorticity and its advection [cs,h]=contourf(x/1000,y/1000,vor_adv,9);
caxis([-1.2e-9, 1.2e-9]), hold on
[cs,h]=contour(x/1000,y/1000,vor,'linewidth',2);
clabel(cs,h,'LabelSpacing',400) axis([-3000,3000,-1000,1000])
title('Vorticity and vorticity advection') xlabel('x (km)'), ylabel('y (km)')
Plot contour
Handel colormap & save figure
% Figure2: plot Geopotential and vorticity figure(2)
subplot(2,1,1) % geopotential ...
subplot(2,1,2) % vorticity advection ...
colorbar('southoutside') colormap('jet')
colorbar
% save graphical current figure (gcf) as PDF saveas(gcf,'geo_vorticity.pdf')