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="VR">
13
<title>Sage and Linear Algebra Worksheet</title>
14
<subtitle>FCLA Section VR</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>Vector Representations</title>
23
24
<p>It is easy to form vector representations of vectors in <m>\mathbb{C}^n</m>.</p>
25
26
<p>We get a nonstandard basis quickly from the columns of a nonsingular matrix. The keyword <c>algorithm='unimodular'</c> requests a matrix with determinant <m>1</m>.</p>
27
28
<sage><input>
29
n = 6
30
A = random_matrix(QQ, n, algorithm='unimodular', upper_bound=9)
31
A
32
</input></sage>
33
34
<p>The columns of <c>A</c> become the <q>user basis</q> of a vector space.</p>
35
36
<sage><input>
37
B = A.columns()
38
V = (QQ^n).subspace_with_basis(B)
39
V
40
</input></sage>
41
42
43
<sage><input>
44
u = random_vector(QQ, n)
45
u
46
</input></sage>
47
48
<p>Now, we get values of the invertible linear transformation <m>\rho_B</m> with the Sage method <c>.coordinate_vector()</c> method of the vector space.</p>
49
50
<sage><input>
51
c = V.coordinate_vector(u)
52
c
53
</input></sage>
54
55
<p>The inverse linear transformation is also available as the <c>.linear_combination_of_basis()</c> method of the vector space.</p>
56
57
<sage><input>
58
round_trip = V.linear_combination_of_basis(c)
59
round_trip
60
</input></sage>
61
62
<p>And the automated check:</p>
63
64
<sage><input>
65
u == round_trip
66
</input></sage>
67
68
<p>Notice that this is something we could do <q>by hand</q> with just reduced row-echelon form. The coordinitization of <c>u</c> relative to the basis <c>B</c> is just a (unique) solution to a linear system.</p>
69
70
<sage><input>
71
aug = column_matrix(B + [u])
72
aug.rref()
73
</input></sage>
74
75
<p>The following stanza will always return <c>True</c> as we <q>coordinatize</q> and then use the coordinates to form a linear combination of the basis.</p>
76
77
<sage><input>
78
w = random_vector(QQ, n)
79
x = V.coordinate_vector(w)
80
y = V.linear_combination_of_basis(x)
81
y == w
82
</input></sage>
83
</section>
84
85
<!-- Might be better to compute something of interest in abstract vector space by coordinatizing -->
86
<section>
87
<title>Abstract Vector Spaces</title>
88
89
<p>Sage does not implement abstract vector spaces. It presumes we have <q>nice</q> standard bases available and can apply an intermediate coordinatization ourselves.</p>
90
91
<!-- [[1, 1, 2, 5], [-2, -1, -3, -8], [2, 1, 4, 7], [-2, 1, 3, -7]] -->
92
<!-- (-33/14, 1/2, 1, 1) -->
93
<exercise>
94
<statement>
95
<p>In <m>P_3</m>, the vector space of polynomials with degree at most <m>3</m>, find the vector representation of <m>p = x^{3} + x^{2} + \frac{1}{2} \, x - \frac{33}{14}</m> relative to the basis for <m>P_3</m>: <md>
96
<mrow>B = \{&amp;
97
5x^{3} + 2x^{2} + x + 1,\,
98
-8x^{3} - 3x^{2} - x - 2,</mrow>
99
<mrow>&amp; 7x^{3} + 4x^{2} + x + 2,\,
100
-7x^{3} + 3x^{2} + x - 2\}</mrow>
101
</md>.</p>
102
103
<p>Hint: Coordinatize with respect to the basis <m>\left\{1, x, x^2, x^3\right\}</m>.</p>
104
</statement>
105
</exercise>
106
107
108
<sage><input>
109
A = matrix(QQ, [[1, -2, 2, -2], [1, -1, 1, 1], [2, -3, 4, 3], [5, -8, 7, -7]])
110
B = A.columns()
111
B
112
</input></sage>
113
114
<p><c>B</c> is a basis, since <c>A</c> is nonsingular.</p>
115
116
<sage><input>
117
A.is_singular()
118
</input></sage>
119
120
<p>Now coordinatize <c>p</c>.</p>
121
122
<sage><input>
123
p = vector(QQ, [-33/14, 1/2, 1, 1])
124
p
125
</input></sage>
126
127
<p>We'll get a coordinatization old-style.</p>
128
129
<sage><input>
130
aug = column_matrix(B + [p])
131
r = aug.rref()
132
r
133
</input></sage>
134
135
<p>Let's check to see if this is right and we can recover <c>p</c>.</p>
136
137
<sage><input>
138
soln = r.column(4)
139
round_trip = sum([soln[i]*B[i] for i in range(4)])
140
round_trip, round_trip == p
141
</input></sage>
142
</section>
143
144
<xi:include href="../legal.xml" />
145
146
</article>
147
</pretext>
148
149