LinAlg hwk 1 Answers

577 days ago by danielm

# problem 8a A= Matrix(QQ, [[12, 4, 18], [3, -5, 4]]) A.echelon_form() 
       
[    1     0 53/36]
[    0     1  1/12]
[    1     0 53/36]
[    0     1  1/12]
# we need to do computations with complex numbers a+bi # where a, b are rational # (sage could do complex numerical computations, but we want exact) # so define CQ complex rationals, before used pure rationals QQ # CQ.<i> = QQ.extension(x^2 + 1); CQ 
       
Number Field in i with defining polynomial x^2 + 1
Number Field in i with defining polynomial x^2 + 1
# problem 8b A= Matrix(CQ, [[1+i, 1, 1], [3, -2+i, 3+7*i]]) A.echelon_form() 
       
[               1                0  31/37*i + 36/37]
[               0                1 -67/37*i + 32/37]
[               1                0  31/37*i + 36/37]
[               0                1 -67/37*i + 32/37]
# problem 9a A= Matrix(QQ, [[2, 4, -3, 6, 18], [3, -2, 7, -1, -10], [1, -1, 5, -8, 12], [7, -3, -6, -2, 7]]) A.echelon_form() 
       
[         1          0          0          0  5453/2374]
[         0          1          0          0 15605/2374]
[         0          0          1          0 -1076/1187]
[         0          0          0          1 -6175/2374]
[         1          0          0          0  5453/2374]
[         0          1          0          0 15605/2374]
[         0          0          1          0 -1076/1187]
[         0          0          0          1 -6175/2374]
# problem 9b A= Matrix(QQ, [[1, 1, -5, 8, 16], [4, -3, 7, -2, -13], [1,2,5,-12, 9]]) A.echelon_form() 
       
[      1       0       0  106/97  341/97]
[      0       1       0 -200/97  581/97]
[      0       0       1 -174/97 -126/97]
[      1       0       0  106/97  341/97]
[      0       1       0 -200/97  581/97]
[      0       0       1 -174/97 -126/97]
def gelim(A, m, n): # # This is a function to perform Gaussian Elimination of A matrix mxn # ( notice this is without partial pivoting) # # A matrix # m number of rows # n number of columns # column=0 for row in range (0,m-1): # search for each rows pivot pivot=A[row, column] while ((pivot==0) and (column<n)): i=row+1 while ((pivot==0) and (i<m)): if (A[i,column]==0): # if this candidate is zero, try next row i=i+1 else: # great, this is the pivot; switch rows for j in range(0,n): v=A[row, j] A[row, j] = A[i,j] A[i, j] = v pivot = A[row, column]; if (pivot==0): # no pivots in this column? try next. column=column+1; if (pivot!=0): # if there is a pivot, perform elimination. for i in range(row+1, m): c=A[i,column]/pivot; for j in range(0,n): A[i,j]= A[i, j] - c* A[row, j]; column=column+1; return A 
       
# problem 10a A= Matrix(QQ, [[4, 6, -9, 2], [2, -5, 3, -6], [1, 0, 4, 9]]) gelim(A, 3, 4) 
       
[     4      6     -9      2]
[     0     -8   15/2     -7]
[     0      0 155/32 157/16]
[     4      6     -9      2]
[     0     -8   15/2     -7]
[     0      0 155/32 157/16]
# problem 10b A= Matrix(CQ, [[1, i, -1, -i], [1+i, i-1, -1-i, 1-i], [i, -1, -i, 1]]) gelim(A,3,4) 
       
[ 1  i -1 -i]
[ 0  0  0  0]
[ 0  0  0  0]
[ 1  i -1 -i]
[ 0  0  0  0]
[ 0  0  0  0]
# Problem 13A A= Matrix(CQ, [[1, i+1, -1],[1-i, 1, -1-i],[i, -1, -i]]) A.echelon_form() 
       
[1 0 0]
[0 1 0]
[0 0 1]
[1 0 0]
[0 1 0]
[0 0 1]
# Problem 13B B= Matrix(QQ, [[3, 1, 2, -5], [1, -2, 3, 2],[2, 1, 4, -3], [1, 0, 2, 5]]) B.echelon_form() 
       
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
[1 0 0 0]
[0 1 0 0]
[0 0 1 0]
[0 0 0 1]
# Problem 14A A= Matrix(QQ, [[3, 7, -1], [2, 0, 4], [7, 7, 7]]) rank(A) 
       
2
2
# Problem 14B B= Matrix(QQ, [[4, 4, 2, -1], [2, 2, 3, 2],[ 1, -3, 4, -1], [5, 0, 2, 0]]) rank(B) 
       
4
4
# Problem 17 A= Matrix(CQ, [[1, i, -1, -i], [1+i, i-1, -1-i, 1-i], [i, -1, -i, 1]]) B= Matrix(CQ, [[0,1],[1, i], [-i, 1], [1,0]]) A*B 
       
[     i     -1]
[ i - 1 -i - 1]
[    -1     -i]
[     i     -1]
[ i - 1 -i - 1]
[    -1     -i]
# Problem 18 A= Matrix(QQ, [[3, -2, 1, 2, 1], [1, 1, -1, -1, -2], [2, -1, 3, 0, 4]]) A.echelon_form() 
       
[     1      0      0  -1/13  -4/13]
[     0      1      0 -17/13  -3/13]
[     0      0      1  -5/13  19/13]
[     1      0      0  -1/13  -4/13]
[     0      1      0 -17/13  -3/13]
[     0      0      1  -5/13  19/13]
# Problem 19 A= Matrix(QQ, [[6, 0, -1], [5, -1, 4], [2, 2, 3]]) B= Matrix(QQ, [[5, -5, -2], [1, 0, 3], [-7, 12, 1]]) 2*A-3*B, A+B, B^2, A^2, B*A, A*B 
       
(
[ -3  15   4]  [11 -5 -3]  [ 34 -49 -27]  [34 -2 -9]  [  1   1 -31]
[  7  -2  -1]  [ 6 -1  7]  [-16  31   1]  [33  9  3]  [ 12   6   8]
[ 25 -32   3], [-5 14  4], [-30  47  51], [28  4 15], [ 20 -10  58],

[ 37 -42 -13]
[ -4  23  -9]
[ -9  26   5]
)
(
[ -3  15   4]  [11 -5 -3]  [ 34 -49 -27]  [34 -2 -9]  [  1   1 -31]
[  7  -2  -1]  [ 6 -1  7]  [-16  31   1]  [33  9  3]  [ 12   6   8]
[ 25 -32   3], [-5 14  4], [-30  47  51], [28  4 15], [ 20 -10  58],

[ 37 -42 -13]
[ -4  23  -9]
[ -9  26   5]
)