% Problem 1
format rat;
% (a)
B = [
 1  -2    0   0   -9   -8;
 3  -5   -4   1  -29  -27;
-1   2    0   1   11   11;
-4   6   82  -6   32   26
];
% (b)
B(2,:) = B(2,:) - 3 * B(1,:)
B(3,:) = B(3,:) + B(1,:)
B(4,:) = B(4,:) + 4 * B(1,:)
B(4,:) = B(4,:) + 2 * B(2,:)
B([3 4],:) = B([4 3],:)
% (c)
B(3,:) = B(3,:) / 74
B(3,:) = B(3,:) + 2/37 * B(4,:)
B(2,:) = B(2,:) - B(4,:)
B(2,:) = B(2,:) + 4 * B(3,:)
B(1,:) = B(1,:) + 2 * B(2,:)
% (d)
rref(B)
% (e)
% The solution of this system in parametric vector form is
% x1 = 17 * x5 - 20
% x2 = 4 * x5 - 6
% x3 = 0
% x4 = -2 * x5 + 3
% x5 is free

clear;

% Problem 2
format rat
% (a)
syms a
syms b
% (b)
A = [
1 3;
3 8
]
rref(A)
% (c)
B = [
8 -5 a;
4  1 b
]
rref(B)
% w1 = a/28 + 5*b/28
% w2 = 2*b/7 - a/7

clear;

% Problem 3
format rat;
% (a)
A = [
 1   1   1    2   -2;
-4  -3  -7  -17    4;
 2   3   0   -3  -12;
 3   2   2    7   15
]
rref(A)
% (b)
% The fourth column is not a pivot column
% (c)
% Suppose these vectors are v1, v2, v3, v4, v5. If we let the free variable x4 = 1, then a linear dependence could be -3 * v1 + 3 * v2 - 2 * v3 + v4 = 0
% (d)
% The linear system Ax = 0 has nontrivial solution
% (e)
% Yes, since there is a pivot in every row

clear;

% Problem 4
format short
% (a)
A = [
cos(pi/10)  -sin(pi/10);
sin(pi/10)   cos(pi/10)
]
% (b)
B = [
cos(pi/12)  -sin(pi/12);
sin(pi/12)   cos(pi/12)
]
A * B - B * A
% (c)
% rotation operations commute
% (d)
C = A * B
t = acos(C(1,1))
format rat;
t / pi
% (e)
format short;
A1 = [
cos(-pi/10)  -sin(-pi/10);
sin(-pi/10)   cos(-pi/10)
]
A1 - inv(A)
% (f)
L0 = [
1  0;
0 -1
]
L1 = A * L0 * A1
% (g)
L1 * L0 - L0 * L1
% (h)
D = L1 * L0
t = acos(D(1,1))
format rat;
t / pi

clear;

% Problem 5
format rat;
% (a)
A = [
2  1  8;
6  4  3;
5  2  5
]
B = [A  eye(3,3)]
C = rref(B)
C(:,[4,5,6])
% (b)
inv(A)

clear;

% Problem 6
format rat;
% (a)
A = [
  1   0   0  0;
-10   5   0  0;
 11   0  -3  0;
 -4  12  -7  2
]
B = [
-1   2   0   1;
 2   2   3   3;
 0   1  -1  -1;
 2  -1   3   1
]
det(A)
det(B)
% (b)
% Cofactor expansion
% (c)
C = A * B
det(C)
% (d)
% det(C) = det(A) * det(B)

clear;

% Problem 7
% (a)
syms a b c d
A = [
a  b;
c  d
]
% (b)
inv(A)
% (c)
syms e f g h i
B = [
a  b  c
d  e  f
g  h  i
]
inv(B)
% (d)
det(B) * inv(B)
B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
      -1              2              0              1             11       
      -4              6             82             -6             32       

  Column 6

      -8       
      -3       
      11       
      26       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
       0              0              0              1              2       
      -4              6             82             -6             32       

  Column 6

      -8       
      -3       
       3       
      26       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
       0              0              0              1              2       
       0             -2             82             -6             -4       

  Column 6

      -8       
      -3       
       3       
      -6       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
       0              0              0              1              2       
       0              0             74             -4             -8       

  Column 6

      -8       
      -3       
       3       
     -12       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
       0              0             74             -4             -8       
       0              0              0              1              2       

  Column 6

      -8       
      -3       
     -12       
       3       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
       0              0              1             -2/37          -4/37    
       0              0              0              1              2       

  Column 6

      -8       
      -3       
      -6/37    
       3       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              1             -2       
       0              0              1              0              0       
       0              0              0              1              2       

  Column 6

      -8       
      -3       
       0       
       3       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1             -4              0             -4       
       0              0              1              0              0       
       0              0              0              1              2       

  Column 6

      -8       
      -6       
       0       
       3       


B =

  Columns 1 through 5

       1             -2              0              0             -9       
       0              1              0              0             -4       
       0              0              1              0              0       
       0              0              0              1              2       

  Column 6

      -8       
      -6       
       0       
       3       


B =

  Columns 1 through 5

       1              0              0              0            -17       
       0              1              0              0             -4       
       0              0              1              0              0       
       0              0              0              1              2       

  Column 6

     -20       
      -6       
       0       
       3       


ans =

  Columns 1 through 5

       1              0              0              0            -17       
       0              1              0              0             -4       
       0              0              1              0              0       
       0              0              0              1              2       

  Column 6

     -20       
      -6       
       0       
       3       


A =

       1              3       
       3              8       


ans =

       1              0       
       0              1       

 
B =
 
[8, -5, a]
[4,  1, b]
 
 
ans =
 
[1, 0, a/28 + (5*b)/28]
[0, 1,   (2*b)/7 - a/7]
 

A =

       1              1              1              2             -2       
      -4             -3             -7            -17              4       
       2              3              0             -3            -12       
       3              2              2              7             15       


ans =

       1              0              0              3              0       
       0              1              0             -3              0       
       0              0              1              2              0       
       0              0              0              0              1       


A =

    0.9511   -0.3090
    0.3090    0.9511


B =

    0.9659   -0.2588
    0.2588    0.9659


ans =

     0     0
     0     0


C =

    0.8387   -0.5446
    0.5446    0.8387


t =

    0.5760


ans =

      11/60    


A1 =

    0.9511    0.3090
   -0.3090    0.9511


ans =

   1.0e-15 *

         0         0
         0   -0.1110


L0 =

     1     0
     0    -1


L1 =

    0.8090    0.5878
    0.5878   -0.8090


ans =

         0   -1.1756
    1.1756         0


D =

    0.8090   -0.5878
    0.5878    0.8090


t =

    0.6283


ans =

       1/5     


A =

       2              1              8       
       6              4              3       
       5              2              5       


B =

  Columns 1 through 5

       2              1              8              1              0       
       6              4              3              0              1       
       5              2              5              0              0       

  Column 6

       0       
       0       
       1       


C =

  Columns 1 through 5

       1              0              0            -14/51         -11/51    
       0              1              0              5/17          10/17    
       0              0              1              8/51          -1/51    

  Column 6

      29/51    
     -14/17    
      -2/51    


ans =

     -14/51         -11/51          29/51    
       5/17          10/17         -14/17    
       8/51          -1/51          -2/51    


ans =

     -14/51         -11/51          29/51    
       5/17          10/17         -14/17    
       8/51          -1/51          -2/51    


A =

       1              0              0              0       
     -10              5              0              0       
      11              0             -3              0       
      -4             12             -7              2       


B =

      -1              2              0              1       
       2              2              3              3       
       0              1             -1             -1       
       2             -1              3              1       


ans =

     -30       


ans =

     -12       


C =

      -1              2              0              1       
      20            -10             15              5       
     -11             19              3             14       
      32              7             49             41       


ans =

     360       

 
A =
 
[a, b]
[c, d]
 
 
ans =
 
[ d/(a*d - b*c), -b/(a*d - b*c)]
[-c/(a*d - b*c),  a/(a*d - b*c)]
 
 
B =
 
[a, b, c]
[d, e, f]
[g, h, i]
 
 
ans =
 
[ (e*i - f*h)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g), -(b*i - c*h)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g),  (b*f - c*e)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g)]
[-(d*i - f*g)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g),  (a*i - c*g)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g), -(a*f - c*d)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g)]
[ (d*h - e*g)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g), -(a*h - b*g)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g),  (a*e - b*d)/(a*e*i - a*f*h - b*d*i + b*f*g + c*d*h - c*e*g)]
 
 
ans =
 
[e*i - f*h, c*h - b*i, b*f - c*e]
[f*g - d*i, a*i - c*g, c*d - a*f]
[d*h - e*g, b*g - a*h, a*e - b*d]