function Dy = Nsprings(t,y)
% Equations of motion for N masses connected with springs

    global N;  % Number of masses 

    range = 1:N;            % Indexes of positions
    Dy(range) = y(range+N); % d/dt position = velocity
    
    Dy(N+1) = y(2)-y(1);    % first mass acceleration
    Dy(2*N) = y(N-1)-y(N);  % last mass acceleration
    
    range = 2:N-1;          % Indexes of "inside" mass positions
    Dy(range+N) = y(range+1) - 2*y(range) + y(range-1);
    
    Dy = Dy';               % transpose
end
    
    