1 function waterwave2
3
4 n = 64; % grid size5 g = 9.8; % gravitational constant6 dt = 0.01; % hardwired timestep7 dx = 1.0;8 dy = 1.0;9 nplotstep = 8; % plot interval10 ndrops = 5; % maximum number of drops11 dropstep = 500; % drop interval12 D = droplet(1.5,21); % simulate a water drop13
14 % Initialize graphics15
16 [surfplot,top,start,stop] = initgraphics(n);17
18 % Outer loop, restarts.19
20 while get(stop,'value') == 021 set(start,'value',0)22
23 H = ones(n+2,n+2); U = zeros(n+2,n+2); V = zeros(n+2,n+2);24 Hx = zeros(n+1,n+1); Ux = zeros(n+1,n+1); Vx = zeros(n+1,n+1);25 Hy = zeros(n+1,n+1); Uy = zeros(n+1,n+1); Vy = zeros(n+1,n+1);26 ndrop = ceil(rand*ndrops);27 nstep = 0;28
29 % Inner loop, time s