📚 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="MR">12<title>Sage and Linear Algebra Worksheet</title>13<subtitle>FCLA Section MR</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 and some Bases</title>2223<p>In this section we define a linear transformation from <m>\mathbb{C}^6</m> to <m>\mathbb{C}^4</m>. The definition is a <m>4\times 6</m> matrix of rank <m>4</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<sage><input>26m, n = 4, 627A = random_matrix(QQ, m, n, algorithm='echelonizable', rank=m, upper_bound=9)28A29</input></sage>3031<sage><input>32T = linear_transformation(A, side='right')33T34</input></sage>3536<p>And we construct two random bases, one for the domain and one for the codomain, extracted from the columns of unimodular matrices.</p>3738<sage><input>39Dmat = random_matrix(QQ, n, n, algorithm='unimodular', upper_bound=9)40D = Dmat.columns()41D42</input></sage>434445<sage><input>46Cmat = random_matrix(QQ, m, m, algorithm='unimodular', upper_bound=9)47C = Cmat.columns()48C49</input></sage>50</section>5152<section>53<title>A Matrix Representation, Old Style</title>5455<p>We will coordinatize the outputs of the linear transformation, for inputs from the basis of the domain, relative to the basis of the codomain, and pack them in a matrix.</p>5657<p>Outputs on the domain basis first.</p>5859<sage><input>60outputs = [T(b) for b in D]61outputs62</input></sage>6364<p>We make a vector space for the codomain, with the desired basis.</p>6566<sage><input>67VC = (QQ^m).subspace_with_basis(C)68VC69</input></sage>7071<p>Now, coordinate versions of the outputs.</p>7273<sage><input>74coord = [VC.coordinate_vector(t) for t in outputs]75coord76</input></sage>7778<p>And then we pack them into a matrix.</p>7980<sage><input>81rep = column_matrix(coord)82rep83</input></sage>8485<p>Does the representation <q>work</q> as it should? We need a vector space for the domain before we can check.</p>8687<sage><input>88VD = (QQ^n).subspace_with_basis(D)89VD90</input></sage>9192<p>OK, coordinatize input, multiply by representation matrix, un-coordinatize (linear combination). This is the fundamental Theorem FTMR at work.</p>9394<sage><input>95u = random_vector(QQ, 6)96out = VC.linear_combination_of_basis(rep*VD.coordinate_vector(u))97u, out, T(u) == out98</input></sage>99100<p>Nice.</p>101</section>102103<section>104<title>A Matrix Representation, Sage Style</title>105106<p>Now we do it Sage style. The matrix of the linear transformation first, as we like to see it.</p>107108<sage><input>109T.matrix(side='right')110</input></sage>111112<p>Now we replace the domain and codomain with new vector spaces, carrying different bases. We are not really <q>restricting</q> the domain and codomain, we are replacing them by the same vector space, but each has a different basis.</p>113114<sage><input>115S = T.restrict_domain(VD).restrict_codomain(VC)116rep2 = S.matrix(side='right')117rep2118</input></sage>119120<p>Bingo! This is representation we found above. A one-liner in Sage.</p>121122<sage><input>123rep2 == rep124</input></sage>125</section>126127<section>128<title>Sneak Preview</title>129130<p>Ponder the following computation <mdash /> matrix representations and nonsingular matrices with columns from the two bases.</p>131132<sage><input>133S.matrix(side='right') - Cmat.inverse()*T.matrix(side='right')*Dmat134</input></sage>135136<p>Notice how Sage is conflicted about if <c>S</c> and <c>T</c> are equal or not.</p>137138<sage><input>139S == T140</input></sage>141142<sage><input>143S.is_equal_function(T)144</input></sage>145</section>146147<xi:include href="../legal.xml" />148149</article>150</pretext>151152153