% Control3_1.m
% Solution to problem 1 of control 3. 2017/04/21
% J.M.Soler

% Set parameters
clear
p = [0,5];      % bolt positions on ceeling (m)
m = [2,3,5];    % particle masses (kg)
k = zeros(5,5);
k(1,2) = 20;    % spring constants (N/m)
k(1,3) = 50;
k(2,3) = 80;
k(1,4) = 40;
k(2,5) = 30;
k = k+k';       % make matrix k symmetric

% Find mass positions
r = equilibrium_3_masses(m,k,p)

% Plot masses as red circles
plot(r(1,:),r(2,:),'.r','MarkerSize',40)

% Plot springs as black lines
hold on
r = [r,[p;0,0]];  % add bolt positions
for i1 = 1:4
    for i2 = i1+1:5
        if k(i1,i2)>0
            plot([r(1,i1),r(1,i2)],[r(2,i1),r(2,i2)],'k')
        end
    end
end
hold off
axis equal
axis([-0.5,5.5,-2.5,0])
xlabel('x (m)')
ylabel('y (m)')
