📚 The CoCalc Library - books, templates and other resources
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}{<} \newcommand{\gt}{>} \newcommand{\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="LT"></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 LT</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"><article class="introduction" id="introduction-1"><h5 class="heading"><span></span></h5></article></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-1">Sage has very capable linear transformations from \(\mathbb{Q}^n\) to \(\mathbb{Q}^m\text{.}\)</p></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">Creation via Symbolic Functions</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-2">Start with a symbolic function.</p></div>
var('x1 x2 x3 x4') f(x1, x2, x3, x4) = (x1 + 2*x2 + x3 + 5*x4, x1 + 5*x2 + 4*x3 + 8*x4, -x2 - x3 - x4)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-3">Then specify the domain and codomain. We need to be careful about how <code class="code-inline tex2jax_ignore">T</code> prints, Sage likes rows.</p></div>
T = linear_transformation(QQ^4, QQ^3, f) T
%auto %html(hide=True) <div class="mathbook-content"><p id="p-4">At a most basic level, <code class="code-inline tex2jax_ignore">T</code> behaves as a function.</p></div>
u = random_vector(ZZ, 4, x=-9, y=9).change_ring(QQ) u, T(u)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-5">We can check Theorem LTTZZ, zero goes to zero.</p></div>
z4 = zero_vector(QQ, 4) z3 = zero_vector(QQ, 3) z4, T(z4), T(z4) == z3
%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">Creation via Matrices</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-6">We can also create a linear transformation from a matrix, as in Theorem MBLT, with one caveat. For a matrix \(A\text{,}\) the default is to create the function \(T(\mathbf{v})=\mathbf{v}A\text{.}\) The keywords option <code class="code-inline tex2jax_ignore">side='right'</code> will indicate that we want to put the vector on the right of the matrix.</p></div>
A = matrix(QQ, [[1, 2, 1, 5], [1, 5, 4, 8], [0, -1, -1, -1]]) S = linear_transformation(A, side='right')
%auto %html(hide=True) <div class="mathbook-content"><p id="p-7">Notice that we do not have to specify the domain or codomain, these are inferred from the size and type of the matrix. <code class="code-inline tex2jax_ignore">S</code> is not new, it is exactly the linear transformation <code class="code-inline tex2jax_ignore">T</code> above.</p></div>
S == T
%auto %html(hide=True) <div class="mathbook-content"><p id="p-8">Again, notice how <code class="code-inline tex2jax_ignore">S</code> prints — the matrix representation is the transpose of what we like to use. This does not <em class="emphasis">change</em> the linear transformation as a function, it just changes how we think about it (we like linear combinations of columns, Sage likes linear combinations of rows).</p></div>
A, S
%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">Creation via Values on a Basis</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-9">Starting with a domain and a codomain, we can provide a list of the images of basis vectors for the domain.</p></div>
v1 = vector(QQ, [1, 1, 0]) v2 = vector(QQ, [2, 5, -1]) v3 = vector(QQ, [1, 4, -1]) v4 = vector(QQ, [5, 8, -1]) R = linear_transformation(QQ^4, QQ^3, [v1, v2, v3, v4])
%auto %html(hide=True) <div class="mathbook-content"><p id="p-10">That's right — same function again.</p></div>
R == T
%auto %html(hide=True) <div class="mathbook-content"><p id="p-11">We can check how this construction works.</p></div>
d3 = R.domain().basis()[2] R(d3); R(d3) == v3
%auto %html(hide=True) <div class="mathbook-content"><p id="p-12">We can give the domain an alternate basis and create a different linear transformation, despite seemingly having the same construction. First we build the domain with a different user basis.</p></div>
u1 = vector(QQ, [1, 0, 0, 0]) u2 = vector(QQ, [1, 1, 0, 0]) u3 = vector(QQ, [1, 1, 1, 0]) u4 = vector(QQ, [1, 1, 1, 1]) dom4 = (QQ^4).subspace_with_basis([u1, u2, u3, u4]) dom4
L = linear_transformation(dom4, QQ^3, [v1, v2, v3, v4]) L
%auto %html(hide=True) <div class="mathbook-content"><p id="p-13">Even though the matrix representation prints the same, this is not the same function, we will need ideas from Chapter R before we can understand the difference.</p></div>
R(u3), L(u3)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-14">This code should consistently return <code class="code-inline tex2jax_ignore">False</code>.</p></div>
v = random_vector(QQ, 4) R(v) == L(v)
%auto %html(hide=True) <div class="mathbook-content"><section class="section" id="section-4"><h6 class="heading hide-type"> <span class="type">Section</span> <span class="codenumber">4</span> <span class="title">Basic Properties</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-15">Illustrations with <code class="code-inline tex2jax_ignore">T</code>.</p></div>
T.domain()
T.codomain()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-16">A defining property, so always <code class="code-inline tex2jax_ignore">True</code>.</p></div>
u = random_vector(QQ, 4) v = random_vector(QQ, 4) u, v, T(u+v) == T(u) + T(v)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-17">A defining property, so also always <code class="code-inline tex2jax_ignore">True</code>.</p></div>
alpha = (QQ).random_element() u = random_vector(QQ, 4) alpha, u, T(alpha*u) == alpha*T(u)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-18">We can do “arithmetic” with linear transformations, though the addition seems to allow bad things to happen.</p></div>
R+S
%auto %html(hide=True) <div class="mathbook-content"><p id="p-19">Scalar multiples also, and they are well-behaved.</p></div>
12*T
%auto %html(hide=True) <div class="mathbook-content"><p id="p-20">The following is wrong. (In other words, there is a bug in Sage.)</p></div>
P = R + L P
%auto %html(hide=True) <div class="mathbook-content"><p id="p-21">As we can see…</p></div>
Q = L + R Q.is_equal_function(P)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-22">The problem is that Sage is simply adding the matrices representing the linear transformations, without checking that they are defined using domains with the <em class="emphasis">same</em> basis. We will understand the subtlety better in Chapter R.</p></div>
%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-23">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>