%===================================================================
% QUIZ 1
%===================================================================
% Problem 1
A = [1 3 1 1;2 -2 1 2;3 1 2 -1];
b = [3; 8; -1];
x = A/b 
% Matlab's answer:
% x = [ 0.7500 ] =  3/4
%     [-0.2500 ] = -1/4
%     [    0   ] =  0
%     [ 3.0000 ] =  3
% is found by setting the free variable x_3 = 0
% If we set x_3 = a, then the full answer is:
% x =  3/4  - 5/8*a
%   = -1/4  - 1/8*a
%   =  0    +     a
%   =  3
% to verify answer write
% x = y + a*z; 
  y = [3/4; -1/4; 0; 3];
  z = [-5/8; -1/8; 1; 0];
% Then compute A*x = A*(y + a*z)= A*y + a*(A*z).
% Matlab gives:
  b1 = A*y
  b2 = A*z
% b1 = A*y = [3; 8; -1]= b and b2 = A*z = [0; 0; 0], so indeed A*x = b
%====================================================================
% Problem 2
A = [1 0 1;2 2 3;3 3 4];
Ainv = A^-1
% Matlab's answer:
% Ainv =  [ 1.0000   -3.0000    2.0000]
%         [-1.0000   -1.0000    1.0000]
%         [      0    3.0000   -2.0000]
%===================================================================
% Problem 3
% Elimination gives
% A = [1  1  3  |  2] ---> [1  1  3  |  2]
%     [1  2  4  |  3]      [0  1  1  |  1]
%     [1  3  a  |  b]      [0  0 a-5 |b-4]
%  if a =/= 5, then the matrix is nonsingular and the system has a
%     unique solution for any value of b
%  if a=5 and b=4 then the system is consistent and x_3 is a free
%     variable; there are infinitely many solutions
%  if a=5 and b=/=4 then the system is inconsistent
%===================================================================
% Problem 4
% Suppose A has an echelon form with no free variables. We do not know
% if there are rows of zeros at the end. Herein lies the main issue
% with this problem: we do not know if A is square (in which case no
% free variables implies no zero rows at the end) or rectangular mXn
% with m>n, in which case there will be zero rows at the lower part of 
% the echelon form of A. All we know is that n<=m (if n>m then there
% would be free variables). All the questions propose a certain fact
% about A. For that fact to be TRUE, it must be implied by the given
% information, for general A, b. 
% If it is not true in general, then the answer is FALSE. 
% 1. for Ax=b to have infinitely many solutions, that requires the 
%         presence of free variables. FALSE
% 2-3. Ax=b will be consistent if the echelon form of the augmented
%         matrix [A|b] has a zero in the b-column (after reduction!)
%         whenever the rest of that row is zero. Otherwise it will be
%         inconsistent. Hence both statements are FALSE in general.
% 4. If A is square and has no free variables, then it is nonsingular.
%         However, A is not necessarily square, and hence the concept
%         "nonsingular" does not apply in general. FALSE
% 5. Ax=0 is always consistent, with the solution x=0. Since there are
%         no free variables, there are no other solutions. TRUE
%===================================================================
