% This is the M-file for solving the set of linear equations 
% described in EXAMPLE 2.2.

%
% read in matrices A and B:
%
A = zeros(19);
A(1,1) = 1; A(1,4) = -1.33;
A(2,2) = 1; A(2,5) = -1.33;
A(3,3) = 1; A(3,6) = -1.33;
A(4,4) = 1; A(4,9) = -3;
A(5,5) = 1; A(5,10) = -3;
A(6,6) = 1; A(6,11) = -3;
A(7,7) = 1; A(7,9) = 1;
A(8,8) = 1;
A(9,9) = 1; A(9,10) = -0.67; A(9,11) = 1;
A(10,10) = 1;
A(11,8) = 1; A(11,11) = 1;
A(12,12) = 1; A(12,14) = -1.33;
A(13,13) = 1; A(13,15) = -1.33;
A(14,14) = 1; A(14,18) = -3;
A(15,15) = 1; A(15,19) = -3;
A(16,9) = -1; A(16,16) = 1; A(16,18) = 1;
A(17,11) = -1; A(17,17) = 1;
A(18,18) = 1; A(18,19) = -0.05;
A(19,10) = -1; A(19,19) = 1;

b = zeros(19,1);
b(7,1) = 8000;
b(8,1) = 800;
b(10,1) = 1000;
b(11,1) = 1000;

%
% solve for the component flow rate of each stream using Gaussian 
% elimination:
%
x = A\b

%=========
% results
%=========

%>> linear2_2

%x =

%   1.0e+03 *

%    1.8753  = W3 (kg/hr)
%    3.9900  = A3 (kg/hr)
%    0.7980  = R3 (kg/hr)
%    1.4100  = W5 (kg/hr)
%    3.0000  = A5 (kg/hr)
%    0.6000  = R5 (kg/hr)
%    7.5300  = W6 (kg/hr)
%    0.8000  = R6 (kg/hr)
%    0.4700  = W7 (kg/hr)
%    1.0000  = A7 (kg/hr)
%    0.2000  = R7 (kg/hr)
%    0.1995  = W9 (kg/hr)
%    3.9900  = A9 (kg/hr)
%    0.1500  = W11(kg/hr)
%    3.0000  = A11(kg/hr)
%    0.4200  = W12(kg/hr)
%    0.2000  = R12(kg/hr)
%    0.0500  = W13(kg/hr)
%    1.0000  = A13(kg/hr)
