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

%
% read in process parameters:
%
a = 0.72;
b = 0;
G = 66.7;
L = 40.8;

%
% read in initial conditions
%
x0 = 0; y7(1) = 0.2; y7(2) = 0.3;

%
% read in matrices A and B:
%
A = zeros(6);
A(1,1) = -(L+G*a);
A(2,1) = L;
A(1,2) = G*a;
A(2,2) = -(L+G*a);
A(3,2) = L;
A(2,3) = G*a;
A(3,3) = -(L+G*a);
A(4,3) = L;
A(3,4) = G*a;
A(4,4) = -(L+G*a);
A(5,4) = L;
A(4,5) = G*a;
A(5,5) = -(L+G*a);
A(6,5) = L;
A(5,6) = G*a;
A(6,6) = -(L+G*a);

B1 = zeros(6,1);
B1(1,1) = -L*x0;
B1(6,1) = -G*a*(y7(1)-b)/a;

B2 = zeros(6,1);
B2(1,1) = -L*x0;
B2(6,1) = -G*a*(y7(2)-b)/a;

%
% solve for the tray compositions:
%

%
% if you want to display the results with long format, use:
% (see "help format" for more info.)
%
%format long

%
% use matrix inversion:
%
x1 = inv(A)*B1
x2 = inv(A)*B2

%
% for better numerical accuracy, use Gaussian elimination:
%
x1 = A\B1
x2 = A\B2


%
%=========
% results
%=========
%>> linear2_1
%

% results using matrix inversion

%x1 =                     
%
%    0.0614
%    0.1136
%    0.1579
%    0.1955
%    0.2275
%    0.2547


%x2 =

%    0.0921
%    0.1703
%    0.2368
%    0.2933
%    0.3413
%    0.3820
%
% results using matrix division

%x1 =

%    0.0614
%    0.1136
%    0.1579
%    0.1955
%    0.2275
%    0.2547

%x2 =

%    0.0921
%    0.1703
%    0.2368
%    0.2933
%    0.3413
%    0.3820
