% TAM 203, Spring 2007
% HW Problem 13.83
% Friday, April 20, 2007
% by Kevin Rompala

% To solve for the requested unknowns we need to solve a linear system of 6
% equations and 6 unknowns. The 6 equations are - linear momentum balance
% on mass C in the j-direction, angular momentum balance on drums B and C,
% the constraint of an inextensible rope, and two no-slip constraints on
% the rope and the two drums. The six unkowns are - the acceleration of
% mass C (y'' measured from the ground), the angular accelerations of drums A 
% (theta_a'') and B (theta_b''), the tension in the rope between mass C and 
% drum A (t_1) and the tension between drum A and B (t_2), and the acceleration 
% of the right-hand end of the rope (x'' in the i-direction). The equations 
% are as follows:
%
% lmb_c: t_1 - m_c*g = m_c*diff(y,t,2);
% amb_a: t_1*r_a - t_2*r_a = -i_a*diff(theta_a,t,2);
% amb_b: -t_2*r_b + F*r_b = i_b*diff(theta_b,t,2);
% rope: diff(y,t,2) = diff(x,t,2);
% no_slip_1: diff(y,t,2) = r_a*diff(theta_a,t,2);
% no_slip_2: diff(x,t,2) = r_b*diff(theta_b,t,2);

% Clear workspace and screen.
clear; clc;

% Define problem constants.
m_a = 10; m_b = 5; m_c = 20; % kg
r_a = 0.3; r_b = 0.2; % m
g = 10; % m/s^2
i_a = 1/2*m_a*r_a^2; % kg*m^2
i_b = 1/2*m_b*r_b^2; % kg*m^2
F = 310; % N

% Coefficients of unknown quantities from the six equations in matrix form.
A = [m_c, 0, 0, 0, -1, 0;       % lmb_c
    0, 0, -i_a, 0, -r_a, r_a;   % amb_a
    0, 0, 0, i_b, 0, r_b;       % amb_b
    1, -1, 0, 0, 0, 0;          % rope
    1, 0, -r_a, 0, 0, 0;        % no_slip_1
    0, 1, 0, -r_b, 0 0];        % no_slip_2

% RHS of six equations in vector form.
b = [-m_c*g; 0; F*r_b; 0; 0; 0];

% Solve the linear system using Matlab's "\" operator. In other words
% solution = inv(A)*b.
solution = A\b;

% Return solutions.
sprintf('The angular acceleration of drum B is %0.2g m/s^2 in the k-direction.',solution(4))
sprintf('The acceleration of mass C is %0.2g m/s^2 in the j-direction.',solution(1))
sprintf('The tension in the rope between mass C and drum A is %0.3g N.',solution(5))