Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
1
<?xml version="1.0" encoding="UTF-8" ?>
2
3
<!-- Sage and Linear Algebra Worksheets -->
4
<!-- Robert A. Beezer -->
5
<!-- Copyright 2017-2019 License: CC BY-SA -->
6
<!-- See COPYING for more information -->
7
8
<pretext xmlns:xi="http://www.w3.org/2001/XInclude">
9
10
<xi:include href="../worksheetinfo.xml" />
11
12
<article xml:id="SD">
13
<title>Sage and Linear Algebra Worksheet</title>
14
<subtitle>FCLA Section SD</subtitle>
15
16
<!-- header inclusion needs -xinclude switch on xsltproc -->
17
<frontmatter>
18
<xi:include href="../header.xml" />
19
</frontmatter>
20
21
<section>
22
<title>Similarity</title>
23
24
<p>We manufacture two matrices that are similar, and use Sage to check. A <q>unimodular</q> matrix is one with determinant 1. A unimodular matrix with integer entries will have an inverse with integer entries (that is a theorem, and Exercise PDM.M20).</p>
25
26
<sage><input>
27
A = random_matrix(ZZ, 10, x = -9, y = 9).change_ring(QQ)
28
S = random_matrix(QQ, 10, algorithm='unimodular', upper_bound=9)
29
B = S.inverse()*A*S
30
A, B
31
</input></sage>
32
33
<p>This next command might be broken, and might even just hang. My fault. It will be fixed, using rational canonical form, for Sage 7.6. See <url href="https://trac.sagemath.org/ticket/18505">Trac ticket <hash />18505</url> for the details.</p>
34
35
<sage><input>
36
A.is_similar(B)
37
</input></sage>
38
</section>
39
40
<section>
41
<title>Diagonalization</title>
42
43
<p>These two matrices are from the earlier demo for Section EE. First is diagonalizable, second is not. The easiest way to see the difference is with the <c>eigenmatrix</c> commands.</p>
44
45
<exercise>
46
<statement>
47
<p>Diagonalize the matrix <m>A</m>.</p>
48
</statement>
49
</exercise>
50
51
<sage><input>
52
A = matrix(QQ, [
53
[-31, -23, -16, 12, 120, -17],
54
[ -3, 7, 0, -12, 60, -21],
55
[-28, -14, -9, -4, 152, -30],
56
[-36, -20, -16, -1, 192, -32],
57
[ -9, -5, -4, 0, 47, -8],
58
[ -1, 1, 0, -4, 20, -3]
59
])
60
A
61
</input></sage>
62
63
<p><c>S</c>, the matrix whose columns are eigenvectors, will <q>diagonalize</q> <c>A</c>.</p>
64
65
<sage><input>
66
D, S = A.eigenmatrix_right()
67
D, S
68
</input></sage>
69
70
<sage><input>
71
S.inverse()*A*S == D
72
</input></sage>
73
74
<p>Here is an equivalent formulation.</p>
75
76
<sage><input>
77
A*S == S*D
78
</input></sage>
79
80
<exercise>
81
<statement>
82
<p>Now, in contrast, a matrix that is not diagonalizable. Try to diagonalize the matrix <m>C</m>.</p>
83
</statement>
84
</exercise>
85
86
<sage><input>
87
C = matrix(QQ, [
88
[128, 20, 44, -50, 236, -18, -330, -565],
89
[ -23, -16, -5, 6, -40, 27, 62, 128],
90
[ -44, -12, -15, 16, -78, 20, 110, 207],
91
[ -2, 10, -4, 3, -10, -23, 20, -9],
92
[ -61, 5, -25, 27, -116, -26, 153, 225],
93
[ -12, -12, -1, 2, -20, 24, 34, 82],
94
[ -23, -3, -8, 9, -42, 2, 57, 99],
95
[ 13, 6, 3, -4, 23, -12, -35, -72]
96
])
97
C
98
</input></sage>
99
100
<sage><input>
101
D, S = C.eigenmatrix_right()
102
D, S
103
</input></sage>
104
105
<p>The zero columns in <c>S</c> tell us that at least one eigenvalue has a geometric multiplicity strictly less than the algebraic multiplicity of the eigenvalue. So by Theorem DMFE the matrix <c>C</c> is not diagonalizable.</p>
106
107
<p>A second consequence of the zero columns of <c>S</c> is that it will not be an invertible matrix. But the output from Sage still obeys a fundamental relationship.</p>
108
109
<sage><input>
110
C*S == S*D
111
</input></sage>
112
113
<p>Perhaps simpler is the built-in function <c>.is_diagonalizable()</c>.</p>
114
115
<sage><input>
116
A.is_diagonalizable()
117
</input></sage>
118
119
<sage><input>
120
C.is_diagonalizable()
121
</input></sage>
122
</section>
123
124
<section>
125
<title>Nearly Diagonalizable</title>
126
127
<p>A matrix that is not diagonalizable will always be similar to a matrix that is <em>almost</em> diagonalizable. The <q>nearly diagonal</q> matrix is called the <term>Jordan canonical form</term> of the matrix.</p>
128
129
<exercise>
130
<statement>
131
<p>While beyond the scope of this course, use Sage to compute the Jordan canonical form for the matrix <c>C</c>. Notice the eigenvalues of <c>C</c> on the diagonal and the 1's on the <term>super-diagonal</term>.</p>
132
133
<p>Peculiarly, the similarity matrix need not be computed to get the form, and it is a significant computational expense. So we ask for it explicitly.</p>
134
</statement>
135
</exercise>
136
137
<sage><input>
138
J, T = C.jordan_form(transformation=True)
139
J, T
140
</input></sage>
141
142
<p>The transformation matrix, <c>T</c>, is invertible and will <q>almost diagonalize</q> <c>C</c>.</p>
143
144
<sage><input>
145
T.inverse()*C*T == J
146
</input></sage>
147
148
<exercise>
149
<statement>
150
<p><term>Rational canonical form</term> is another interesting version of this idea, try <c>.rational_form()</c> on <c>C</c>. And if you do, then execute the following two cells and see if the coefficients look familiar. Learn more about <term>companion matrices</term> if this makes you curious.</p>
151
</statement>
152
</exercise>
153
154
<sage><input>
155
C.rational_form()
156
</input></sage>
157
158
<sage><input>
159
C.fcp()
160
</input></sage>
161
162
<sage><input>
163
((x-1)^3*(x+2)^3).expand()
164
</input></sage>
165
</section>
166
167
<xi:include href="../legal.xml" />
168
169
</article>
170
</pretext>
171
172