%derive 2 DoF symbolically
%This is how to get the equations of motion into one big
%line of code

syms t z x v x0  L1 L2 L2dot L3 T1 T2s T3 T2d xdot v1dot v2dot vdot
syms z1 z2 z3 z4
syms d omega w1 w2 L L1 L2 L3 L10 L20 L30 m1 m2 k1 k2 k3 c2

z=[z1 z2 z3 z4];
x=z(1:2);  v=z(3:4);  % Unpack z into variables with good names
x0 = d* cos(omega*t); % The 'forcing function' 

L1    = x(1) - x0;            % Calculate lengths
L2    = x(2) -(x(1) + w1); 
L2dot = v(2) - v(1);
L3    = L  - (x(2) + w2);

T1  = k1 * (L1 - L10);    % Calculate tensions
T2s = k2 * (L2 - L20);
T3  = k3 * (L3 - L30);
T2d = c2 * L2dot;

%The next 3 lines are the 4 ODEs
xdot  = v;   % first two ODEs
v1dot = (T2s + T2d - T1)/m1; % These 2 ODEs are ...
v2dot = (T3  - T2d -T2s)/m2; % ... F=ma for the two masses

vdot  = [v1dot v2dot];         % Store the 2 v's together

%Here is the resulting algabraic mess!
zdot= [xdot vdot]             % four numbers: 2 x's and 2 v's


