% -----------------------------------------------------
% linear_3parachutists.m
% -----------------------------------------------------
% Suppose a team of three parachutists is connected 
% by a weightless cord while free-falling at a 
% velocity of 5 m/s. Calculate the tension in each 
% section of the cord and the acceleration of the team. 
% This problem is adopted from Chapra and Canale's 
% Numerical Methods for Engineers. 
% -----------------------------------------------------
% Notes: Use Gaussian Elimination. 
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

% clear all variables and the command window
clear
clc

% Define given parameters
m1 = 70;      % mass in kg
m2 = 60;
m3 = 40;
c1 = 10;      % drag coefficients in kg/s
c2 = 14;
c3 = 17;

% Their velocity and acceleration due to gravity
v = 5;    % m/s
g = 9.81; % m/s^2

% Define the system of equations
A = [m1, 1, 0; m2, -1, 1; m3, 0, -1];
b = [m1*g-c1*v; m2*g-c2*v; m3*g-c3*v];

% Solve for x in Ax=b using Gaussian Elimination
x = A\b;

% Objective is to find the acceleration, and tensions
a = x(1);
T1 = x(2);
T2 = x(3);

% Displaying values
fprintf('The acceleration is\n\ta = %.2f m/s^2\n\n',a)
fprintf('The tensions are\n')
fprintf('\tT1 = %.2f N\n',T1)
fprintf('\tT2 = %.2f N\n',T2)
