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="NM">
13
<title>Sage and Linear Algebra Worksheet</title>
14
<subtitle>FCLA Section NM</subtitle>
15
16
<!-- header inclusion needs -xinclude switch on xsltproc -->
17
<frontmatter>
18
<xi:include href="../header.xml" />
19
</frontmatter>
20
21
22
<p>First, a guaranteed nonsingular <m>5\times 5</m> matrix, created at random.</p>
23
24
<sage>
25
<input>
26
A = random_matrix(QQ, 5, algorithm="unimodular", upper_bound=20)
27
A
28
</input>
29
</sage>
30
31
<exercise>
32
<statement>
33
<p>Augment with the zero vector, using the matrix method <c>.augment()</c> and the vector constructor <c>zero_vector(QQ, 5)</c>. Then row-reduce to use Definition NM. Or instead, do not augment and apply Theorem NMRRI.</p>
34
</statement>
35
</exercise>
36
37
<sage />
38
39
<exercise>
40
<statement>
41
<p>Build some random vectors with <c>random_vector(QQ, 5)</c>, augment the matrix and row-reduce. There will always be a unique solution to the linear system represented by the augmented matrix. This is Theorem NMUS.</p>
42
</statement>
43
</exercise>
44
45
<sage />
46
47
<p>Instead<mdash />cheap, easy and powerful:</p>
48
49
<sage>
50
<input>A.is_singular()</input>
51
</sage>
52
53
<p>Now, a carefully crafted singular matrix.</p>
54
55
<sage>
56
<input>
57
B = matrix(QQ, [[ 7, -1, -12, 21, -8],
58
[-3, 3, 0, -9, 6],
59
[ 3, 3, -12, 9, 0],
60
[ 2, 3, -10, 6, 1],
61
[-2, 2, 0, -6, 4]])
62
B
63
</input>
64
</sage>
65
66
<exercise>
67
<statement>
68
<p>Augment with the zero vector and row-reduce (Definition NM), or don't augment and row-reduce (Theorem NMRRI).]</p>
69
</statement>
70
</exercise>
71
72
<sage />
73
74
<exercise>
75
<statement>
76
<p>A random vector of constants will only rarely build a consistent system when paired with <c>B</c>. Try it. But this is not a theorem, see the vector <c>c</c> below.</p>
77
</statement>
78
</exercise>
79
80
<sage />
81
82
<p>Instead<mdash />cheap, easy and powerful:</p>
83
84
<sage>
85
<input>B.is_singular()</input>
86
</sage>
87
88
<p>Two carefully crafted vectors for linear systems with <c>B</c> as coefficient matrix.</p>
89
90
<sage>
91
<input>
92
c = vector(QQ, [17,-15,-3,-5,-10])
93
d = vector(QQ, [-3,1,-2,1,2])
94
</input>
95
</sage>
96
97
<exercise>
98
<statement>
99
<p>Which of these two column vectors will create a consistent system for this singular coefficient matrix? (Stay tuned.)</p>
100
</statement>
101
</exercise>
102
103
<sage />
104
105
<p>A null space is called a <term>right kernel</term> in Sage. It's description contains a lot of things we do not understand yet.</p>
106
107
<sage>
108
<input>
109
NS = B.right_kernel()
110
NS
111
</input>
112
</sage>
113
114
<exercise>
115
<statement>
116
<p>But we can test membership in the null space, which is the most basic property of a set. Try <c>u in NS</c> and then repeat with <c>v</c>.</p>
117
</statement>
118
</exercise>
119
120
<sage>
121
<input>u = vector(QQ, [0,0,3,4,6])</input>
122
</sage>
123
124
<sage />
125
126
<sage>
127
<input>v = vector(QQ, [1,0,0,5,-2])</input>
128
</sage>
129
130
<sage />
131
132
<xi:include href="../legal.xml" />
133
134
</article>
135
136
</pretext>
137
138