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="CB">
13
<title>Sage and Linear Algebra Worksheet</title>
14
<subtitle>FCLA Section CB</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>A Linear Transformation, Two Vector Spaces, Four Bases</title>
23
24
<p>In this section we define a linear transformation from <m>\mathbb{C}^{3}</m> to <m>\mathbb{C}^{7}</m> using a randomly selected matrix. The definition is a <m>7\times 3</m> matrix of rank <m>3</m> that we will use to multiply input vectors with a matrix-vector product. It is not important if the linear transformation is injective and/or surjective.</p>
25
26
<p>We will build two representations, using a total of four bases — two for the domain and two for the codomain.</p>
27
28
<sage><input>
29
m, n = 7, 3
30
A = random_matrix(QQ, m, n, algorithm='echelonizable', rank=n, upper_bound=9)
31
A
32
</input></sage>
33
34
<sage><input>
35
T = linear_transformation(A, side='right')
36
T
37
</input></sage>
38
39
<p>The four bases, associated with the two vector spaces.</p>
40
41
<sage><input>
42
D1mat = random_matrix(QQ, n, n, algorithm='unimodular', upper_bound=9)
43
D1 = D1mat.columns()
44
D1
45
VD1 = (QQ^n).subspace_with_basis(D1)
46
#
47
D2mat = random_matrix(QQ, n, n, algorithm='unimodular', upper_bound=9)
48
D2 = D2mat.columns()
49
D2
50
VD2 = (QQ^n).subspace_with_basis(D2)
51
#
52
C1mat = random_matrix(QQ, m, m, algorithm='unimodular', upper_bound=9)
53
C1 = C1mat.columns()
54
C1
55
VC1 = (QQ^m).subspace_with_basis(C1)
56
#
57
C2mat = random_matrix(QQ, m, m, algorithm='unimodular', upper_bound=9)
58
C2 = C2mat.columns()
59
C2
60
VC2 = (QQ^m).subspace_with_basis(C2)
61
</input></sage>
62
63
<exercise>
64
<statement>
65
<p>Check out a few of these bases by just asking Sage to display them.</p>
66
</statement>
67
</exercise>
68
69
<sage><input>
70
D1
71
</input></sage>
72
73
<p>Now we build two <em>different</em> representations.</p>
74
75
<sage><input>
76
rep1 = T.restrict_domain(VD1).restrict_codomain(VC1)
77
rep1.matrix(side='right')
78
</input></sage>
79
80
<sage><input>
81
rep2 = T.restrict_domain(VD2).restrict_codomain(VC2)
82
rep2.matrix(side='right')
83
</input></sage>
84
85
</section>
86
87
<section>
88
<title>Change of Basis Matrices</title>
89
90
<p>A natural way to build a change-of-basis matrix in Sage is to adjust the bases for domain and range of the identity linear transformation by supplying an identity matrix to the linear tansformation constructor.</p>
91
92
<sage><input>
93
identity_domain = linear_transformation(QQ^n, QQ^n, identity_matrix(n))
94
identity_domain
95
</input></sage>
96
97
<sage><input>
98
CBdom = identity_domain.restrict_domain(VD1).restrict_codomain(VD2)
99
CBdom_mat = CBdom.matrix(side='right')
100
CBdom_mat
101
</input></sage>
102
103
<p>This matrix should convert between the two bases for the domain. Here's a check of Theorem CB.</p>
104
105
<sage><input>
106
u = random_vector(QQ, n)
107
u1 = VD1.coordinate_vector(u)
108
u2 = VD2.coordinate_vector(u)
109
u, u1, u2, u2 == CBdom_mat*u1
110
</input></sage>
111
112
<p>Same drill in the codomain.</p>
113
114
<sage><input>
115
identity_codomain = linear_transformation(QQ^m, QQ^m, identity_matrix(m))
116
identity_codomain
117
</input></sage>
118
119
<sage><input>
120
CBcodom = identity_codomain.restrict_domain(VC1).restrict_codomain(VC2)
121
CBcodom_mat = CBcodom.matrix(side='right')
122
CBcodom_mat
123
</input></sage>
124
125
<p>And here is the check on Theorem MRCB. Convert from domain basis 1 to domain basis 2, use the second representation, then convert back from codomain basis 2 to codomain basis 1 and get as a result the representation relative to the first bases.</p>
126
127
<sage><input>
128
rep1.matrix(side='right') == CBcodom_mat.inverse()*rep2.matrix(side='right')*CBdom_mat
129
</input></sage>
130
131
</section>
132
133
<section>
134
<title>A Diagonal Representation</title>
135
136
<p>We specialize to linear transformations with equal domain and codomain.</p>
137
138
<p>First a matrix representation using a square matrix.</p>
139
140
<sage><input>
141
A = matrix(QQ,
142
[[ -2, 3, -20, 15, 1, 30, -5, 17],
143
[-27, -38, -30, -50, 268, -73, 210, -273],
144
[-12, -24, -7, -30, 142, -48, 100, -160],
145
[ -3, -15, 35, -32, 35, -57, 20, -71],
146
[ -9, -9, -10, -10, 65, -11, 50, -59],
147
[ -3, -6, -20, 0, 58, 1, 40, -55],
148
[ 3, 0, 5, 0, -10, -3, -12, 1],
149
[ 0, 3, 0, 5, -19, 10, -15, 25]])
150
T = linear_transformation(A, side='right')
151
T
152
</input></sage>
153
154
<p>A basis of <m>\mathbb{C}^8</m>. And a vector space with this basis.</p>
155
156
<sage><input>
157
v1 = vector(QQ, [-4, -6, -1, 7, -2, -4, 1, 0])
158
v2 = vector(QQ, [ 3, -10, -6, -6, -2, 0, 0, 1])
159
v3 = vector(QQ, [ 0, -9, -4, -1, -3, -1, 1, 0])
160
v4 = vector(QQ, [ 1, -12, -8, -5, -3, -2, 0, 1])
161
v5 = vector(QQ, [ 0, 3, 2, 2, 1, 0, 0, 0])
162
v6 = vector(QQ, [ 1, 0, 0, -2, 0, 1, 0, 0])
163
v7 = vector(QQ, [ 0, 0, 2, 3, 0, 0, 1, 0])
164
v8 = vector(QQ, [ 3, -4, -2, -3, 0, 0, 0, 1])
165
B = [v1, v2, v3, v4, v5, v6, v7, v8]
166
V = (QQ^8).subspace_with_basis(B)
167
</input></sage>
168
169
<sage><input>
170
S = T.restrict_domain(V).restrict_codomain(V)
171
S.matrix(side='right')
172
</input></sage>
173
174
<p>That's a nice representation! Where did the basis come from?</p>
175
176
<sage><input>
177
A.eigenvalues()
178
</input></sage>
179
180
<p>Some (right) eigenvectors.</p>
181
182
<sage><input>
183
(A - 3).right_kernel(basis='pivot').basis()
184
</input></sage>
185
186
<p>Eigenvalues are a property of the linear transformation.</p>
187
188
<sage><input>
189
T.eigenvalues()
190
</input></sage>
191
192
<p>Bases for the eigenspaces depend on the representation, but the actual eigenvectors are also a property of the linear transformation.</p>
193
194
<sage><input>
195
S.eigenvectors()
196
</input></sage>
197
198
<sage><input>
199
T.eigenvectors()
200
</input></sage>
201
202
<p>We could do the same thing, but in the style of Section SD, using a change-of-basis matrix.</p>
203
204
<sage><input>
205
identity = linear_transformation(QQ^8, QQ^8, identity_matrix(8))
206
identity
207
</input></sage>
208
209
<sage><input>
210
CB = identity.restrict_domain(V).restrict_codomain(QQ^8)
211
CB
212
</input></sage>
213
214
<p>Here is similarity, in disguise.</p>
215
216
<sage><input>
217
CBmat = CB.matrix(side='right')
218
CBmat.inverse()*T.matrix(side='right')*CBmat
219
</input></sage>
220
</section>
221
222
<xi:include href="../legal.xml" />
223
224
</article>
225
</pretext>
226
227