Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 16658

Math 152: Intro to Mathematical Software

2017-02-01

Kiran Kedlaya; University of California, San Diego

adapted from lectures by William Stein, University of Washington

Lecture 10: Linear Algebra (part 1)

%md Announcements: - The week 4 feedback survey is still open: (URL removed) - The "solutions" for HW 3, i.e., the original TeX files that I used to make the answer samples, are available as a new handout. - If you think you are on the waitlist and did *not* receive an email yesterday asking you to reconfirm your interest in enrolling in the class, please let me know before I leave class today.

Announcements:

# You should read this matrix? # and this vector?
matrix.block
#A = matrix(2, 3, [[1,2,3], [sqrt(2),5,pi]]) A = matrix(2, 3, [1,2,3, sqrt(2),5,pi]) A
[ 1 2 3] [sqrt(2) 5 pi]
A = matrix([[1,2,3],[sqrt(2), 5, pi]])
A.transpose()
[ 1 sqrt(2)] [ 2 5] [ 3 pi]
show(A)
(12325π)\displaystyle \left(\begin{array}{rrr} 1 & 2 & 3 \\ \sqrt{2} & 5 & \pi \end{array}\right)
v = vector([1, sqrt(2), pi^2]); v
(1, sqrt(2), pi^2)
show(v)
(1,2,π2)\displaystyle \left(1,\,\sqrt{2},\,\pi^{2}\right)
show(A); show(v); show(A*v)
(12325π)\displaystyle \left(\begin{array}{rrr} 1 & 2 & 3 \\ \sqrt{2} & 5 & \pi \end{array}\right)
(1,2,π2)\displaystyle \left(1,\,\sqrt{2},\,\pi^{2}\right)
(3π2+22+1,π3+62)\displaystyle \left(3 \, \pi^{2} + 2 \, \sqrt{2} + 1,\,\pi^{3} + 6 \, \sqrt{2}\right)
v * A.transpose()
(3*pi^2 + 2*sqrt(2) + 1, pi^3 + 6*sqrt(2))
show(A.echelon_form())
(102(π32)225+301π32225)\displaystyle \left(\begin{array}{rrr} 1 & 0 & \frac{2 \, {\left(\pi - 3 \, \sqrt{2}\right)}}{2 \, \sqrt{2} - 5} + 3 \\ 0 & 1 & -\frac{\pi - 3 \, \sqrt{2}}{2 \, \sqrt{2} - 5} \end{array}\right)

2. Standard functions:

  • determinant

  • characteristic polynomial

  • echelon form

  • row space

  • column space

  • rows, columns

  • matrix_from_rows, matrix_from_columns

  • solve

Integers() is ZZ
True
#set_random_seed(28) # put your age here A = random_matrix(QQ, 5) show(A)
(121200010001202021210210220)\displaystyle \left(\begin{array}{rrrrr} 1 & 2 & -\frac{1}{2} & 0 & 0 \\ 0 & -1 & 0 & 0 & 0 \\ -\frac{1}{2} & 0 & 2 & 0 & 2 \\ -1 & 2 & -1 & 0 & 2 \\ 1 & 0 & 2 & 2 & 0 \end{array}\right)
f = A.charpoly() print(f.factor()) parent(f)
(x + 1) * (x^4 - 3*x^3 - 25/4*x^2 + 21*x - 13) Univariate Polynomial Ring in x over Rational Field
B = A +1 show(A) show(B)
(121200010001202021210210220)\displaystyle \left(\begin{array}{rrrrr} 1 & 2 & -\frac{1}{2} & 0 & 0 \\ 0 & -1 & 0 & 0 & 0 \\ -\frac{1}{2} & 0 & 2 & 0 & 2 \\ -1 & 2 & -1 & 0 & 2 \\ 1 & 0 & 2 & 2 & 0 \end{array}\right)
(221200000001203021211210221)\displaystyle \left(\begin{array}{rrrrr} 2 & 2 & -\frac{1}{2} & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ -\frac{1}{2} & 0 & 3 & 0 & 2 \\ -1 & 2 & -1 & 1 & 2 \\ 1 & 0 & 2 & 2 & 1 \end{array}\right)
B.charpoly().factor() B.det()
x * (x^4 - 7*x^3 + 35/4*x^2 + 41/2*x - 145/4) 0
f.base_ring()
Rational Field
f.factor()
x^5 + 3*x^4 + 6*x^3 + 63/4*x^2 + 29*x + 195/8
show(f.change_ring(CC).factor())
(x0.7140039591745892.07933489614716i)(x0.714003959174589+2.07933489614716i)(x+1.285346654498701.03106393820580i)(x+1.28534665449870+1.03106393820580i)(x+1.85731460935178)\displaystyle (x - 0.714003959174589 - 2.07933489614716i) \cdot (x - 0.714003959174589 + 2.07933489614716i) \cdot (x + 1.28534665449870 - 1.03106393820580i) \cdot (x + 1.28534665449870 + 1.03106393820580i) \cdot (x + 1.85731460935178)
E= A.eigenspaces_right()
E[0]act_on_polynomial
(-1.857314609351780?, Vector space of degree 5 and dimension 1 over Algebraic Field User basis matrix: [ 1 3.504212994256084? -0.10512329983419517? 0.3761439167989345? -3.684097802778675?])
len(E)
5
A.determinant()
13
B.echelon_form()
[ 1 0 0 0 -2/3] [ 0 1 0 0 29/36] [ 0 0 1 0 5/9] [ 0 0 0 1 5/18] [ 0 0 0 0 0]
B.row_space()
Vector space of degree 5 and dimension 4 over Rational Field Basis matrix: [ 1 0 0 0 -2/3] [ 0 1 0 0 29/36] [ 0 0 1 0 5/9] [ 0 0 0 1 5/18]
QQ^3
Vector space of dimension 3 over Rational Field
span(QQ, [vector([1,2,3]), vector([4,5,6]), vector([7,8,9])])
Vector space of degree 3 and dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2]
show(A)
(121200010001202021210210220)\displaystyle \left(\begin{array}{rrrrr} 1 & 2 & -\frac{1}{2} & 0 & 0 \\ 0 & -1 & 0 & 0 & 0 \\ -\frac{1}{2} & 0 & 2 & 0 & 2 \\ -1 & 2 & -1 & 0 & 2 \\ 1 & 0 & 2 & 2 & 0 \end{array}\right)
v = vector([1,0,1,1,0])
w = A.solve_right(v); print w
(12/13, 0, -2/13, -4/13, 23/26)
show(A*w, v)
(1,0,1,1,0)\displaystyle \left(1,\,0,\,1,\,1,\,0\right) (1,0,1,1,0)\displaystyle \left(1,\,0,\,1,\,1,\,0\right)
A = matrix([[1,1],[2,3]])
show(A)
(1123)\displaystyle \left(\begin{array}{rr} 1 & 1 \\ 2 & 3 \end{array}\right)
v = vector([1,-1])
show(A, v)
(1123)\displaystyle \left(\begin{array}{rr} 1 & 1 \\ 2 & 3 \end{array}\right) (1,1)\displaystyle \left(1,\,-1\right)
w = A.solve_right(v); w
(4, -3)
show(w*A, v)
(1,1)\displaystyle \left(1,\,-1\right) (1,1)\displaystyle \left(1,\,-1\right)