Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132928 views
License: OTHER
%auto %html(hide=True) <div class="mathbook-content"> <link rel="stylesheet" type="text/css" href="http://buzzard.ups.edu/mathbook-content.css"> <link rel="stylesheet" type="text/css" href="https://aimath.org/mathbook/mathbook-add-on.css"> </div>
%auto %html(hide=True) <div class="mathbook-content"><div class="hidden-content" style="display:none">\( \newcommand{\lt}{&lt;} \newcommand{\gt}{&gt;} \newcommand{\amp}{&amp;} \)</div></div>
%auto %html(hide=True) <div class="mathbook-content"><table width="90%" style="font-size: 200%;"><tr></tr></table></div>
%auto %html(hide=True) <div class="mathbook-content"><section class="article" id="B"></section></div>
%auto %html(hide=True) <div class="mathbook-content"><section class="frontmatter" id="frontmatter-1"></section></div>
%auto %html(hide=True) <div class="mathbook-content"> <h2 class="heading"> <span class="title">Sage and Linear Algebra Worksheet:</span> <span class="subtitle">FCLA Section B</span> </h2> <div class="author"> <div class="author-name">Robert Beezer</div> <div class="author-info">Department of Mathematics and Computer Science<br>University of Puget Sound</div> </div> <div class="date">Fall 2019</div> </div>
%auto %html(hide=True) <div class="mathbook-content"><section class="section" id="section-1"><h6 class="heading hide-type"> <span class="type">Section</span> <span class="codenumber">1</span> <span class="title">Bases</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-1">Five “random” vectors, each with 4 entries, collected into a set <code class="code-inline tex2jax_ignore">S</code>.</p></div>
v1 = vector(QQ, [-4, -2, 3, -11]) v2 = vector(QQ, [-2, 7, 3, 9]) v3 = vector(QQ, [ 6, -4, -7, 5]) v4 = vector(QQ, [-1, 0, 3, -4]) v5 = vector(QQ, [-4, 5, -5, 11]) S = [v1, v2, v3, v4, v5]
%auto %html(hide=True) <div class="mathbook-content"><p id="p-2">Consider the subspace spanned by these five vectors. We will make these vectors the <em class="emphasis">rows</em> of a matrix and row-reduce to see a basis for the space (subspace, or row space, take your pick). This is an application of Theorem BRS.</p></div>
A = matrix(S) A
A.rref()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-3">Sage does this semi-automatically, tossing zero rows for us.</p></div>
W = span(S) B = W.basis() B
%auto %html(hide=True) <div class="mathbook-content"><article class="exercise-like" id="exercise-1"><h6 class="heading"> <span class="type">Demonstration</span> <span class="codenumber">1</span>.</h6> <p id="p-4">Construct a <em class="emphasis">random</em> vector, <code class="code-inline tex2jax_ignore">w</code>, in this subspace by choosing scalars for a linear combination of the vectors we used to build <code class="code-inline tex2jax_ignore">W</code> as a span originally.</p> <p id="p-5">Then use the three <em class="emphasis">basis</em> vectors in <code class="code-inline tex2jax_ignore">B</code> to recreate the vector <code class="code-inline tex2jax_ignore">w</code>. Question: how many ways can you do this? By Theorem VRRB there should always be exactly one way to create <code class="code-inline tex2jax_ignore">w</code> using a linear combination of a basis of <code class="code-inline tex2jax_ignore">W</code>.</p></article></div>
w = *v1 + *v2 + *v3 + *v4 + *v5 w
w in W
*B[0] + *B[1] + *B[2]
%auto %html(hide=True) <div class="mathbook-content"><section class="section" id="section-2"><h6 class="heading hide-type"> <span class="type">Section</span> <span class="codenumber">2</span> <span class="title">Nonsingular Matrices</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-6">We will obtain a basis of \(\mathbb{C}^{10}\) from the columns of a \(10\times 10\) nonsingular matrix.</p></div>
entries = [[ 1, 1, 1, -1, -2, 4, 2, -3, 1, -6], [-2, -1, -2, 2, 4, -7, -4, 5, -1, 7], [ 1, -1, 2, -2, -5, 8, 5, -3, 4, -4], [-1, -2, 0, 1, 0, -5, 0, -3, -5, 6], [ 0, -2, 1, -1, -2, 3, 2, 3, 3, 7], [ 1, 0, 1, -1, -2, 4, 2, 0, 2, 0], [-1, 0, -1, 1, 3, -1, -2, 7, 5, 1], [ 1, 1, 1, -1, -2, 8, 3, 2, 8, -6], [ 0, 2, -1, 1, 2, -1, -2, 2, 2, -6], [ 1, 3, 0, 0, 1, 3, 0, 0, 3, -8]] M = matrix(QQ, entries) M
not M.is_singular()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-7">A totally random vector with 10 entries:</p></div>
v = random_vector(ZZ, 10, x=-9, y=9) v
%auto %html(hide=True) <div class="mathbook-content"><article class="exercise-like" id="exercise-2"><h6 class="heading"> <span class="type">Demonstration</span> <span class="codenumber">2</span>.</h6> <p id="p-8">By Theorem CNMB, the columns of the matrix are a basis of \(\mathbb{C}^{10}\text{.}\) So the vector <code class="code-inline tex2jax_ignore">v</code> should be a linear combination of the columns of the matrix. Verify this fact in three ways.</p> <ol class="decimal"> <li id="li-1">First, the old-fashioned way, thus exposing Theorem NMUS.</li> <li id="li-2">Then, the modern way, with an inverse, since a nonsingular matrix is invertible, thus exposing Theorem SNCM.</li> <li id="li-3">Finally, the Sage way, as described below.</li> </ol></article></div>
aug = M.augment(v) aug.rref()
M.inverse()*v
%auto %html(hide=True) <div class="mathbook-content"><p id="p-9">The Sage way: first create a space with a <dfn class="terminology">user basis</dfn>.</p></div>
X = (QQ^10).subspace_with_basis(M.columns()) X
%auto %html(hide=True) <div class="mathbook-content"><p id="p-10">Sage still carries an <dfn class="terminology">echelonized basis</dfn>, in addition to the <dfn class="terminology">user-installed</dfn> basis.</p></div>
X.basis()
X.echelonized_basis()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-11">Now ask for a coordinatization, relative to the basis in <code class="code-inline tex2jax_ignore">X</code>, thus exposing Theorem VRRB.</p></div>
X.coordinates(v)
%auto %html(hide=True) <div class="mathbook-content"><section class="section" id="section-3"><h6 class="heading hide-type"> <span class="type">Section</span> <span class="codenumber">3</span> <span class="title">Orthonormal Bases</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-12">A particularly simple orthonormal basis of \(\mathbb{C}^3\text{,}\) collected into the set <code class="code-inline tex2jax_ignore">S</code>.</p></div>
v1 = vector(QQ, [1/3, 2/3, 2/3]) v2 = vector(QQ, [2/3, -2/3, 1/3]) v3 = vector(QQ, [2/3, 1/3, -2/3]) S = [v1, v2, v3]
%auto %html(hide=True) <div class="mathbook-content"><article class="exercise-like" id="exercise-3"><h6 class="heading"> <span class="type">Demonstration</span> <span class="codenumber">3</span>.</h6> <p id="p-13">If these vectors are an orthonormal basis, then as the columns of a matrix they should create an orthonormal basis.</p></article></div>
Q = column_matrix(S) Q
Q.conjugate_transpose()*Q
Q.is_unitary()
%auto %html(hide=True) <div class="mathbook-content"><article class="exercise-like" id="exercise-4"><h6 class="heading"> <span class="type">Demonstration</span> <span class="codenumber">4</span>.</h6> <p id="p-14">Build a random vector of size \(3\) and find our ways to express the vector as a (unique) linear combination of the basis vectors. Which method is most efficient?</p></article></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-15">A totally random vector with 3 entries.</p></div>
v = random_vector(ZZ, 3, x=-9, y=9) v
%auto %html(hide=True) <div class="mathbook-content"><p id="p-16">First, the old-fashioned way, thus exposing Theorem NMUS.</p></div>
aug = Q.augment(v) aug.rref()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-17">Now, the modern way, with an inverse, since a nonsingular matrix is invertible, thus exposing Theorem SNCM.</p></div>
Q.inverse()*v
%auto %html(hide=True) <div class="mathbook-content"><p id="p-18">The Sage way. Create a space with a “user basis” and ask for a coordinatization, thus exposing Theorem VRRB.</p></div>
X = (QQ^3).subspace_with_basis(Q.columns()) X.coordinates(v)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-19">Finally, exploiting the orthonormal basis, and computing scalars for the linear combination with an inner product, thus exposing Theorem COB. (Sage's <code class="code-inline tex2jax_ignore">.inner_product()</code> does not conjugate the entries of either vector, so we use the more careful <code class="code-inline tex2jax_ignore">.hermitian_inner_product()</code> vector method instead.)</p></div>
a1 = v1.hermitian_inner_product(v) a2 = v2.hermitian_inner_product(v) a3 = v3.hermitian_inner_product(v) a1, a2, a3
%auto %html(hide=True) <div class="mathbook-content"><article class="conclusion" id="conclusion-1"><h5 class="heading"><span></span></h5></article></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-20">This work is Copyright 2016–2019 by Robert A. Beezer. It is licensed under a <a class="external" href="https://creativecommons.org/licenses/by-sa/4.0/" target="_blank">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</p></div>
%auto %html(hide=True) <div class="mathbook-content"><table width="90%" style="font-size: 200%;"><tr></tr></table></div>