% pluck & visulaize a guitar string % parameters Nx = 101; % elements in a unit-length string dx = 1/(Nx-1); c = 1; % convenient dt = c*dx; % since we require r = 1 f = 0.35; % fraction of length at which string is plucked Nt = 500; % # of time steps % preallocate results Y = zeros(Nx,Nt+2); % establish initial conditions pluckPoint = round(f*Nx); % various types of plucks type = 2; if type == 1 Y(:,1) = [ ((1:pluckPoint)-1)'/(pluckPoint-1) (Nx-(pluckPoint+1:Nx))'/(Nx-pluckPoint) ]; elseif type == 2 Y(:,1) = exp(-0.02*((1:Nx)-pluckPoint).^2); end % copy IC in two places Y(:,2) = Y(:,1); % loop through time for solutions for n = 3:Nt+2 Y(:,n-2:n) = stringFixed(Y(:,n-2:n),c,dt,dx); end % image results clf plot(Y(:,1)) set(gca,'ylim',1.05*[-1 1]) pause for n = 2:size(Y,2) plot(Y(:,n)) set(gca,'ylim',1.05*[-1 1]) pause(0.001) end return