% MATLAB for Recitation 2
% 1.050
% September 13, 2007
% -----------------------------------------------------------------

clear
close all
clc
format short

% exponent matrix with column entries for the BRIDGE example in extended
% dimension bases

% colums:  [Fzlim] [rho] [g] [sigma0] [l] [b] [h]

EM = [0 -1 0 1 1 0 0
    0 -1 0 -1 0 1 0
    1 -1 1 -1 0 0 1
    1 1 0 1 0 0 0 
    -2 0 -2 -2 0 0 0]
    
rankEM = rank(EM)

% trial 1,
A1 = [ EM(:,2) EM(:,3) EM(:,4) EM(:,5) EM(:,7) ]
% CHECK: if det(A) is NOT zero,
%       then A is set of dimensionally independent variables
detA1 = det(A1)
% determinant is zero, so A1 is not a set of dimensionally indepedent
% variables


% trial 2,
A2 = [ EM(:,3) EM(:,4) EM(:,5) EM(:,6) EM(:,7) ]
% CHECK: if det(A) is NOT zero,
%       then A is set of dimensionally independent variables
detA2 = det(A2)
% determinant is non zero. BINGO! A2 is a set of dimensionally indepedent
% variables

% solving linear system of equation

%for Fzlim
b1 = [ EM(:,1) ]
so1 = inv(A2)*b1

%for density rho
b2 = [ EM(:,2) ]
so2 = inv(A2)*b2