function Y = stringFreeFixed(Y,c,dt,dx) %Y = stringFreeFixed(Y,c,dt,dx); % adavnce PDE solution for fixed (right end) & free (left end) 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(:,1), paying attention to BC % free end has unique EOM, so it goes outside space loop Y(1,3) = r2*(Y(2,2) - Y(1,2)) - Y(1,1) + 2*Y(1,2); 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