📚 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="SD">12<title>Sage and Linear Algebra Worksheet</title>13<subtitle>FCLA Section SD</subtitle>1415<!-- header inclusion needs -xinclude switch on xsltproc -->16<frontmatter>17<xi:include href="../header.xml" />18</frontmatter>1920<section>21<title>Similarity</title>2223<p>We manufacture two matrices that are similar, and use Sage to check. A <q>unimodular</q> matrix is one with determinant 1. A unimodular matrix with integer entries will have an inverse with integer entries (that is a theorem, and Exercise PDM.M20).</p>2425<sage><input>26A = random_matrix(ZZ, 10, x = -9, y = 9).change_ring(QQ)27S = random_matrix(QQ, 10, algorithm='unimodular', upper_bound=9)28B = S.inverse()*A*S29A, B30</input></sage>3132<p>This next command might be broken, and might even just hang. My fault. It will be fixed, using rational canonical form, for Sage 7.6. See <url href="https://trac.sagemath.org/ticket/18505">Trac ticket <hash />18505</url> for the details.</p>3334<sage><input>35A.is_similar(B)36</input></sage>37</section>3839<section>40<title>Diagonalization</title>4142<p>These two matrices are from the earlier demo for Section EE. First is diagonalizable, second is not. The easiest way to see the difference is with the <c>eigenmatrix</c> commands.</p>4344<exercise>45<statement>46<p>Diagonalize the matrix <m>A</m>.</p>47</statement>48</exercise>4950<sage><input>51A = matrix(QQ, [52[-31, -23, -16, 12, 120, -17],53[ -3, 7, 0, -12, 60, -21],54[-28, -14, -9, -4, 152, -30],55[-36, -20, -16, -1, 192, -32],56[ -9, -5, -4, 0, 47, -8],57[ -1, 1, 0, -4, 20, -3]58])59A60</input></sage>6162<p><c>S</c>, the matrix whose columns are eigenvectors, will <q>diagonalize</q> <c>A</c>.</p>6364<sage><input>65D, S = A.eigenmatrix_right()66D, S67</input></sage>6869<sage><input>70S.inverse()*A*S == D71</input></sage>7273<p>Here is an equivalent formulation.</p>7475<sage><input>76A*S == S*D77</input></sage>7879<exercise>80<statement>81<p>Now, in contrast, a matrix that is not diagonalizable. Try to diagonalize the matrix <m>C</m>.</p>82</statement>83</exercise>8485<sage><input>86C = matrix(QQ, [87[128, 20, 44, -50, 236, -18, -330, -565],88[ -23, -16, -5, 6, -40, 27, 62, 128],89[ -44, -12, -15, 16, -78, 20, 110, 207],90[ -2, 10, -4, 3, -10, -23, 20, -9],91[ -61, 5, -25, 27, -116, -26, 153, 225],92[ -12, -12, -1, 2, -20, 24, 34, 82],93[ -23, -3, -8, 9, -42, 2, 57, 99],94[ 13, 6, 3, -4, 23, -12, -35, -72]95])96C97</input></sage>9899<sage><input>100D, S = C.eigenmatrix_right()101D, S102</input></sage>103104<p>The zero columns in <c>S</c> tell us that at least one eigenvalue has a geometric multiplicity strictly less than the algebraic multiplicity of the eigenvalue. So by Theorem DMFE the matrix <c>C</c> is not diagonalizable.</p>105106<p>A second consequence of the zero columns of <c>S</c> is that it will not be an invertible matrix. But the output from Sage still obeys a fundamental relationship.</p>107108<sage><input>109C*S == S*D110</input></sage>111112<p>Perhaps simpler is the built-in function <c>.is_diagonalizable()</c>.</p>113114<sage><input>115A.is_diagonalizable()116</input></sage>117118<sage><input>119C.is_diagonalizable()120</input></sage>121</section>122123<section>124<title>Nearly Diagonalizable</title>125126<p>A matrix that is not diagonalizable will always be similar to a matrix that is <em>almost</em> diagonalizable. The <q>nearly diagonal</q> matrix is called the <term>Jordan canonical form</term> of the matrix.</p>127128<exercise>129<statement>130<p>While beyond the scope of this course, use Sage to compute the Jordan canonical form for the matrix <c>C</c>. Notice the eigenvalues of <c>C</c> on the diagonal and the 1's on the <term>super-diagonal</term>.</p>131132<p>Peculiarly, the similarity matrix need not be computed to get the form, and it is a significant computational expense. So we ask for it explicitly.</p>133</statement>134</exercise>135136<sage><input>137J, T = C.jordan_form(transformation=True)138J, T139</input></sage>140141<p>The transformation matrix, <c>T</c>, is invertible and will <q>almost diagonalize</q> <c>C</c>.</p>142143<sage><input>144T.inverse()*C*T == J145</input></sage>146147<exercise>148<statement>149<p><term>Rational canonical form</term> is another interesting version of this idea, try <c>.rational_form()</c> on <c>C</c>. And if you do, then execute the following two cells and see if the coefficients look familiar. Learn more about <term>companion matrices</term> if this makes you curious.</p>150</statement>151</exercise>152153<sage><input>154C.rational_form()155</input></sage>156157<sage><input>158C.fcp()159</input></sage>160161<sage><input>162((x-1)^3*(x+2)^3).expand()163</input></sage>164</section>165166<xi:include href="../legal.xml" />167168</article>169</pretext>170171172