📚 The CoCalc Library - books, templates and other resources
License: OTHER
<?xml version="1.0" encoding="UTF-8" ?>12<!-- Sage and Linear Algebra Worksheets -->3<!-- Robert A. Beezer -->4<!-- Copyright 2017-2019 License: CC BY-SA -->5<!-- See COPYING for more information -->67<pretext xmlns:xi="http://www.w3.org/2001/XInclude">89<xi:include href="../worksheetinfo.xml" />1011<article xml:id="CB">12<title>Sage and Linear Algebra Worksheet</title>13<subtitle>FCLA Section CB</subtitle>1415<!-- header inclusion needs -xinclude switch on xsltproc -->16<frontmatter>17<xi:include href="../header.xml" />18</frontmatter>1920<section>21<title>A Linear Transformation, Two Vector Spaces, Four Bases</title>2223<p>In this section we define a linear transformation from <m>\mathbb{C}^{3}</m> to <m>\mathbb{C}^{7}</m> using a randomly selected matrix. The definition is a <m>7\times 3</m> matrix of rank <m>3</m> that we will use to multiply input vectors with a matrix-vector product. It is not important if the linear transformation is injective and/or surjective.</p>2425<p>We will build two representations, using a total of four bases — two for the domain and two for the codomain.</p>2627<sage><input>28m, n = 7, 329A = random_matrix(QQ, m, n, algorithm='echelonizable', rank=n, upper_bound=9)30A31</input></sage>3233<sage><input>34T = linear_transformation(A, side='right')35T36</input></sage>3738<p>The four bases, associated with the two vector spaces.</p>3940<sage><input>41D1mat = random_matrix(QQ, n, n, algorithm='unimodular', upper_bound=9)42D1 = D1mat.columns()43D144VD1 = (QQ^n).subspace_with_basis(D1)45#46D2mat = random_matrix(QQ, n, n, algorithm='unimodular', upper_bound=9)47D2 = D2mat.columns()48D249VD2 = (QQ^n).subspace_with_basis(D2)50#51C1mat = random_matrix(QQ, m, m, algorithm='unimodular', upper_bound=9)52C1 = C1mat.columns()53C154VC1 = (QQ^m).subspace_with_basis(C1)55#56C2mat = random_matrix(QQ, m, m, algorithm='unimodular', upper_bound=9)57C2 = C2mat.columns()58C259VC2 = (QQ^m).subspace_with_basis(C2)60</input></sage>6162<exercise>63<statement>64<p>Check out a few of these bases by just asking Sage to display them.</p>65</statement>66</exercise>6768<sage><input>69D170</input></sage>7172<p>Now we build two <em>different</em> representations.</p>7374<sage><input>75rep1 = T.restrict_domain(VD1).restrict_codomain(VC1)76rep1.matrix(side='right')77</input></sage>7879<sage><input>80rep2 = T.restrict_domain(VD2).restrict_codomain(VC2)81rep2.matrix(side='right')82</input></sage>8384</section>8586<section>87<title>Change of Basis Matrices</title>8889<p>A natural way to build a change-of-basis matrix in Sage is to adjust the bases for domain and range of the identity linear transformation by supplying an identity matrix to the linear tansformation constructor.</p>9091<sage><input>92identity_domain = linear_transformation(QQ^n, QQ^n, identity_matrix(n))93identity_domain94</input></sage>9596<sage><input>97CBdom = identity_domain.restrict_domain(VD1).restrict_codomain(VD2)98CBdom_mat = CBdom.matrix(side='right')99CBdom_mat100</input></sage>101102<p>This matrix should convert between the two bases for the domain. Here's a check of Theorem CB.</p>103104<sage><input>105u = random_vector(QQ, n)106u1 = VD1.coordinate_vector(u)107u2 = VD2.coordinate_vector(u)108u, u1, u2, u2 == CBdom_mat*u1109</input></sage>110111<p>Same drill in the codomain.</p>112113<sage><input>114identity_codomain = linear_transformation(QQ^m, QQ^m, identity_matrix(m))115identity_codomain116</input></sage>117118<sage><input>119CBcodom = identity_codomain.restrict_domain(VC1).restrict_codomain(VC2)120CBcodom_mat = CBcodom.matrix(side='right')121CBcodom_mat122</input></sage>123124<p>And here is the check on Theorem MRCB. Convert from domain basis 1 to domain basis 2, use the second representation, then convert back from codomain basis 2 to codomain basis 1 and get as a result the representation relative to the first bases.</p>125126<sage><input>127rep1.matrix(side='right') == CBcodom_mat.inverse()*rep2.matrix(side='right')*CBdom_mat128</input></sage>129130</section>131132<section>133<title>A Diagonal Representation</title>134135<p>We specialize to linear transformations with equal domain and codomain.</p>136137<p>First a matrix representation using a square matrix.</p>138139<sage><input>140A = matrix(QQ,141[[ -2, 3, -20, 15, 1, 30, -5, 17],142[-27, -38, -30, -50, 268, -73, 210, -273],143[-12, -24, -7, -30, 142, -48, 100, -160],144[ -3, -15, 35, -32, 35, -57, 20, -71],145[ -9, -9, -10, -10, 65, -11, 50, -59],146[ -3, -6, -20, 0, 58, 1, 40, -55],147[ 3, 0, 5, 0, -10, -3, -12, 1],148[ 0, 3, 0, 5, -19, 10, -15, 25]])149T = linear_transformation(A, side='right')150T151</input></sage>152153<p>A basis of <m>\mathbb{C}^8</m>. And a vector space with this basis.</p>154155<sage><input>156v1 = vector(QQ, [-4, -6, -1, 7, -2, -4, 1, 0])157v2 = vector(QQ, [ 3, -10, -6, -6, -2, 0, 0, 1])158v3 = vector(QQ, [ 0, -9, -4, -1, -3, -1, 1, 0])159v4 = vector(QQ, [ 1, -12, -8, -5, -3, -2, 0, 1])160v5 = vector(QQ, [ 0, 3, 2, 2, 1, 0, 0, 0])161v6 = vector(QQ, [ 1, 0, 0, -2, 0, 1, 0, 0])162v7 = vector(QQ, [ 0, 0, 2, 3, 0, 0, 1, 0])163v8 = vector(QQ, [ 3, -4, -2, -3, 0, 0, 0, 1])164B = [v1, v2, v3, v4, v5, v6, v7, v8]165V = (QQ^8).subspace_with_basis(B)166</input></sage>167168<sage><input>169S = T.restrict_domain(V).restrict_codomain(V)170S.matrix(side='right')171</input></sage>172173<p>That's a nice representation! Where did the basis come from?</p>174175<sage><input>176A.eigenvalues()177</input></sage>178179<p>Some (right) eigenvectors.</p>180181<sage><input>182(A - 3).right_kernel(basis='pivot').basis()183</input></sage>184185<p>Eigenvalues are a property of the linear transformation.</p>186187<sage><input>188T.eigenvalues()189</input></sage>190191<p>Bases for the eigenspaces depend on the representation, but the actual eigenvectors are also a property of the linear transformation.</p>192193<sage><input>194S.eigenvectors()195</input></sage>196197<sage><input>198T.eigenvectors()199</input></sage>200201<p>We could do the same thing, but in the style of Section SD, using a change-of-basis matrix.</p>202203<sage><input>204identity = linear_transformation(QQ^8, QQ^8, identity_matrix(8))205identity206</input></sage>207208<sage><input>209CB = identity.restrict_domain(V).restrict_codomain(QQ^8)210CB211</input></sage>212213<p>Here is similarity, in disguise.</p>214215<sage><input>216CBmat = CB.matrix(side='right')217CBmat.inverse()*T.matrix(side='right')*CBmat218</input></sage>219</section>220221<xi:include href="../legal.xml" />222223</article>224</pretext>225226227