Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132939 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="MR">
13
<title>Sage and Linear Algebra Worksheet</title>
14
<subtitle>FCLA Section MR</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 and some Bases</title>
23
24
<p>In this section we define a linear transformation from <m>\mathbb{C}^6</m> to <m>\mathbb{C}^4</m>. The definition is a <m>4\times 6</m> matrix of rank <m>4</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
<sage><input>
27
m, n = 4, 6
28
A = random_matrix(QQ, m, n, algorithm='echelonizable', rank=m, upper_bound=9)
29
A
30
</input></sage>
31
32
<sage><input>
33
T = linear_transformation(A, side='right')
34
T
35
</input></sage>
36
37
<p>And we construct two random bases, one for the domain and one for the codomain, extracted from the columns of unimodular matrices.</p>
38
39
<sage><input>
40
Dmat = random_matrix(QQ, n, n, algorithm='unimodular', upper_bound=9)
41
D = Dmat.columns()
42
D
43
</input></sage>
44
45
46
<sage><input>
47
Cmat = random_matrix(QQ, m, m, algorithm='unimodular', upper_bound=9)
48
C = Cmat.columns()
49
C
50
</input></sage>
51
</section>
52
53
<section>
54
<title>A Matrix Representation, Old Style</title>
55
56
<p>We will coordinatize the outputs of the linear transformation, for inputs from the basis of the domain, relative to the basis of the codomain, and pack them in a matrix.</p>
57
58
<p>Outputs on the domain basis first.</p>
59
60
<sage><input>
61
outputs = [T(b) for b in D]
62
outputs
63
</input></sage>
64
65
<p>We make a vector space for the codomain, with the desired basis.</p>
66
67
<sage><input>
68
VC = (QQ^m).subspace_with_basis(C)
69
VC
70
</input></sage>
71
72
<p>Now, coordinate versions of the outputs.</p>
73
74
<sage><input>
75
coord = [VC.coordinate_vector(t) for t in outputs]
76
coord
77
</input></sage>
78
79
<p>And then we pack them into a matrix.</p>
80
81
<sage><input>
82
rep = column_matrix(coord)
83
rep
84
</input></sage>
85
86
<p>Does the representation <q>work</q> as it should? We need a vector space for the domain before we can check.</p>
87
88
<sage><input>
89
VD = (QQ^n).subspace_with_basis(D)
90
VD
91
</input></sage>
92
93
<p>OK, coordinatize input, multiply by representation matrix, un-coordinatize (linear combination). This is the fundamental Theorem FTMR at work.</p>
94
95
<sage><input>
96
u = random_vector(QQ, 6)
97
out = VC.linear_combination_of_basis(rep*VD.coordinate_vector(u))
98
u, out, T(u) == out
99
</input></sage>
100
101
<p>Nice.</p>
102
</section>
103
104
<section>
105
<title>A Matrix Representation, Sage Style</title>
106
107
<p>Now we do it Sage style. The matrix of the linear transformation first, as we like to see it.</p>
108
109
<sage><input>
110
T.matrix(side='right')
111
</input></sage>
112
113
<p>Now we replace the domain and codomain with new vector spaces, carrying different bases. We are not really <q>restricting</q> the domain and codomain, we are replacing them by the same vector space, but each has a different basis.</p>
114
115
<sage><input>
116
S = T.restrict_domain(VD).restrict_codomain(VC)
117
rep2 = S.matrix(side='right')
118
rep2
119
</input></sage>
120
121
<p>Bingo! This is representation we found above. A one-liner in Sage.</p>
122
123
<sage><input>
124
rep2 == rep
125
</input></sage>
126
</section>
127
128
<section>
129
<title>Sneak Preview</title>
130
131
<p>Ponder the following computation <mdash /> matrix representations and nonsingular matrices with columns from the two bases.</p>
132
133
<sage><input>
134
S.matrix(side='right') - Cmat.inverse()*T.matrix(side='right')*Dmat
135
</input></sage>
136
137
<p>Notice how Sage is conflicted about if <c>S</c> and <c>T</c> are equal or not.</p>
138
139
<sage><input>
140
S == T
141
</input></sage>
142
143
<sage><input>
144
S.is_equal_function(T)
145
</input></sage>
146
</section>
147
148
<xi:include href="../legal.xml" />
149
150
</article>
151
</pretext>
152
153