% Unit 3 (MATLAB Course @ UAM)
% (c) Alexander Knebe

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% system of masses
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc

%====================================================================
% solve system
%====================================================================
m   = [2, 3, 5];
x4  = 0.0;
x5  = 5.0;
k12 = 20;
k13 = 50;
k14 = 40;
k23 = 80;
k25 = 30;
k = [0.0, k12, k13, k14, 0.0;
     k12, 0.0, k23, 0.0, k25;
     k13, k12, 0.0, 0.0, 0.0;
     k14, 0.0, 0.0, 0.0, 0.0;
     0.0, k25, 0.0, 0.0, 0.0];
 
 p = [x4, x5];
 r = equilib3m(m, k, p)
 
%====================================================================
% plotting
%====================================================================
figure(1), hold on

% masses
plot(x4,0,'x')
plot(x5,0,'x')
plot(r(1,1),r(2,1),'x','MarkerSize',30)
plot(r(1,2),r(2,2),'x','MarkerSize',30)
plot(r(1,3),r(2,3),'x','MarkerSize',30)

% springs
plot([x4,r(1,1)],[0,r(2,1)],'-k')
plot([x5,r(1,2)],[0,r(2,2)],'-k')
plot([r(1,1),r(1,2)],[r(2,1),r(2,2)],'-k')
plot([r(1,1),r(1,3)],[r(2,1),r(2,3)],'-k')
plot([r(1,2),r(1,3)],[r(2,2),r(2,3)],'-k')
xlabel('x (m)')
ylabel('y (m)')

