%Joy Perkinson %1.020 Recitation, 4/17/09 function carplume %Current version of this program has a car that moves and leaves behind a %plume of particles as it goes. %Set system boundaries Xmax = 120; Xmin = 0; %Set initial values Vx = 0; %Wind speed Vy = 0.2; x = 0; %Initial car position y = 0; Vc = 0.3; %Car speed emiss = 2; %Rate of dropping particles, must be an integer dt = 1; %Storing the droped particles %[1stx 1sty, 2ndx 2ndy, 3rdx 3rdy,...] particles = [x y]; t=0; %Time counter while 1 t = t+1; %Increment time counter x = x+Vc*dt; %Tell car to start over if it's passed 120 if x>Xmax particles = []; %Clear array x = 0; %Move car back to start, y is still 0 end %Emit particles for i = 1:emiss particles = [particles; x y]; end %Make particles move randomly if size(particles) == [1 2] particles(1,1) = particles(1,1) + Vx*dt + (rand-0.5)*sqrt(3); particles(1,2) = particles(1,2) + Vy*dt + (rand-0.5)*sqrt(3); else for i=1:length(particles) particles(i,1) = particles(i,1) + Vx*dt + (rand-0.5)*sqrt(3); particles(i,2) = particles(i,2) + Vy*dt + (rand-0.5)*sqrt(3); end end % if t==5 %Decide whether to drop particle % particles = [particles; x1 y1; x2 y2]; % t=0; %Reset time counter % end plot(x,y,'o',particles(:,1),particles(:,2),'.') axis([Xmin-20 Xmax+20 Xmin-20 Xmax-20]) pause(0.01) end