% MATLAB file trajectory_3.m % Trajectory problem for Chapter 3 % This version can be run as a movie to show propagation of streamlines and % parcel trajectories for an initial cluster of N parcels (N=12 in example) % Horizontal motion with zonally propagating sinusoidal wave streamfunction % including a SW-NE tilt of the troughs and ridges and zonal jet structure % Space coordinates are scaled to units of km % 3rd order accuracy time differencing used % Cyclic boundary conditions in zonal direction (parcels are reentrant) % %close all clear all % First define the grid points on which fields are computed: % (Distances are in units of 1000 km). xx=linspace(-3000,3000,30); % 30 gridpoints in x yy=linspace( -1000,1000,20); % 20 gridpoints in y [x,y]=meshgrid(xx*1000,yy*1000); % Sets matrix for grid system in x and y in meters disp('Trajectories are plotted for particles initially clustered near x=0 km') ystartdef = 0; updef=10; cpdef=0; ubdef=0; ystart = 1000*input(' give an initial y position in range -3000 3.e6 X(n)= -6.e6+X(n); end if real(X(n)) < -3.e6 X(n) = 6.e6+X(n); end end if mod(t,tsave*3600)==0 mnpt=mean(X)/1000; set(gca, 'NextPlot', 'replacechildren') nsv = nsv +1; timsv(nsv)=t/(24*3600); stdev(nsv)=std(imag(X))/1000; ymean(nsv)=imag(mnpt); point(nsv)=mnpt; contour(x/1000,y/1000,phi/9.8,v1,'k-'); hold on contour(x/1000,y/1000,phi/9.8,v2,'k--'); plot(real(X)/1000,imag(X)/1000, 'bo', 'MarkerSize',4) plot(real(mnpt),imag(mnpt),'r*','MarkerSize',8) xlabel('x (km)'), ylabel('y (km)') title('Streamfunction and particle position') hold off %make movie H = gca; M(:,nsv) = getframe(H); end t = t +dt; end movie(M) return figure(2) plot(timsv,stdev) ylabel('km'), xlabel('time (days)') title('standard deviation of y position') figure(3) plot(timsv,ymean) ylabel('km'), xlabel('time (days)'), title('mean y position') figure(4) plot(point,'*-') ylabel('y position in km'), xlabel('x position in km'); title('Mean parcel positions at 6 hour intervals')