function Y = stringFixed(Y,c,dt,dx) %Y = stringFixed(Y,c,dt,dx); % adavnce PDE solution for fixed (both ends) string by one time step, % using two previous steps % Y <=> [N,3] matrix of [y(:,n-2) y(:,n-1) y(:,n)], string displacements % c --> wave speed % dt --> time step % dx --> space step (be sure that c <= dx/dt) % a constant calculated here rather than in loop r2 = (c*dt/dx)^2; % loop over space to determine Y(:,3), paying attention to BC for ii = 2:size(Y,1)-1 Y(ii,3) = r2*(Y(ii+1,2) + Y(ii-1,2) -2*Y(ii,2)) - Y(ii,1) + 2*Y(ii,2); end return