function f = bridgeForces( r, m, k )
% Forces on a hanging bridge
% Input:
%   r(2,n)  : coordinates of bridge nodes (m)
%   m       : node'ss mass (kg)
%   k       : cable's spring constant (N/m)
% Output:
%   f(2,n)  : force on each node, with f(:,1)=f(:,n)=0
% J.M.Soler, Feb.2016

g = [0;-9.8];          % gravitational acceleration vector (m/s^2)
n = size(r,2);         % number of nodes

% Find forces
f = zeros(size(r));
for i = 2:n-1
    f(:,i) = - k*(r(:,i)-r(:,i-1)) - k*(r(:,i)-r(:,i+1)) + m*g(:);
end

end
