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="SS">
13
<title>Sage and Linear Algebra Worksheet</title>
14
<subtitle>FCLA Section SS</subtitle>
15
16
<!-- header inclusion needs -xinclude switch on xsltproc -->
17
<frontmatter>
18
<xi:include href="../header.xml" />
19
</frontmatter>
20
21
22
<section>
23
<title>Vector Spaces</title>
24
25
<p>It is easy in Sage to make a reasonable facsimile of <m>\mathbf{C}^n</m>. We just restrict our attention to rational entries rather than complex entries. This vector space contains vectors with 4 slots, each filled with a rational number.</p>
26
27
<sage>
28
<input>
29
V = QQ^4
30
V
31
</input>
32
</sage>
33
34
<exercise>
35
<statement>
36
<p>We can test membership using the word/command <c>in</c>. Try vectors with different numers of slots, and perhaps include the complex number <c>2 + 3*I</c> as an entry.</p>
37
</statement>
38
</exercise>
39
40
<sage />
41
42
</section>
43
44
<section>
45
<title>Vector Form of Solutions to Homogeneous Systems</title>
46
47
<p>These are the coefficient matrix and vector of constants from yesterday's big system that led to a colored matrix in reduced row-echelon form.</p>
48
49
<p>The <c>.right_kernel()</c> method will give the vectors of the vector form of the solutions to a homogeneous system when used with the <c>basis='pivot'</c> option.</p>
50
51
<sage>
52
<input>
53
A = matrix(QQ, [[ 1, 2, 12, 1, 13, 5, 2],
54
[ -2, -3, -21, 0, -13, 2, -5],
55
[ 1, 3, 15, 4, 28, 25, 0],
56
[ -2, -3, -21, -1, -15, -6, -3],
57
[ 1, 1, 9, 1, 4, 9, 1]])
58
b = vector(QQ, [8, -15, 7, -10, 3])
59
</input>
60
</sage>
61
62
<sage>
63
<input>A.right_kernel(basis='pivot')</input>
64
</sage>
65
66
<p>Rows of the <q>basis matrix</q> are vectors in yesterday's linear combination (with scalars <m>x_3</m>, <m>x_5</m>, <m>x_6</m>). This is a spanning set for the null space of the matrix <m>A</m>. See Theorem VFSLS and Theorem SSNS.</p>
67
68
<p>Theorem PSPHS can explain how to use a single solution to the non-homogeneous system and the spanning set of the null space of the coefficient matrix to arrive at all solutions to the system. Here is a single solution to the system.</p>
69
70
<sage>
71
<input>A.solve_right(b)</input>
72
</sage>
73
74
<p>Notice that this vector is the solution when we set each free variable to zero, which is the <q>other</q> vector from yesterday that is not part of the linear combination.</p>
75
</section>
76
77
<section>
78
<title>Spanning Sets</title>
79
80
<p>Example ABS from FCLA.</p>
81
82
<sage>
83
<input>
84
x1 = vector(QQ,[1,1,3,1])
85
x2 = vector(QQ,[2,1,2,-1])
86
x3 = vector(QQ,[7,3,5,-5])
87
x4 = vector(QQ,[1,1,-1,2])
88
x5 = vector(QQ,[-1,0,9,0])
89
W = span([x1, x2, x3, x4, x5])
90
W
91
</input>
92
</sage>
93
94
<exercise>
95
<statement>
96
<p>Make a <q>random</q> linear combination of the five vectors and test for membership (which will be trivially true, repeatedly). Remember to use the <c>*</c> operator for vector scalar multiplication.</p>
97
</statement>
98
</exercise>
99
100
<sage />
101
102
<p>But not any old vector is in <m>W</m>.</p>
103
104
<sage>
105
<input>
106
v = vector(QQ, [1, 1, -3, 2])
107
v in W
108
</input>
109
</sage>
110
111
<p>It should make sense that arbitrary linear combinations are in the span. How did we manufacture a vector <em>not</em> in the span? Stay tuned.</p>
112
</section>
113
114
<xi:include href="../legal.xml" />
115
116
</article>
117
</pretext>
118
119