Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132939 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="EE"></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 EE</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">Eigenvalues and Eigenvectors</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-1">A \(6\times 6\) matrix with “nice” eigenvalues.</p></div>
A = matrix(QQ, [ [-31, -23, -16, 12, 120, -17], [ -3, 7, 0, -12, 60, -21], [-28, -14, -9, -4, 152, -30], [-36, -20, -16, -1, 192, -32], [ -9, -5, -4, 0, 47, -8], [ -1, 1, 0, -4, 20, -3] ]) A
p = A.characteristic_polynomial() p
p.factor()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-2">Eigenvalues are the roots of the characteristic polynomial (Theorem EMRCP), which should be obvious from the factored version, including their (algebraic) multiplicities. Of course, it can be very easy to get these in Sage.</p></div>
A.eigenvalues()
%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-3">Create the singular matrices \(A-\lambda I_6\) for each eigenvalue (we will choose to do two with “random” choices for the eigenvalue). Row-reducing these matrices will exhibit their nonzero nullity.</p></article></div>
(A-( )*identity_matrix(6)).rref()
(A-( )*identity_matrix(6)).rref()
%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-4">Examine the eigenspace for the eigenvalue \(\lambda=3\text{,}\) using Sage's right kernel command and the pivot basis.</p> <p id="p-5">Use a basis for the eigenspace to create eigenvectors of <code class="code-inline tex2jax_ignore">A</code> for the eigenvalue \(\lambda=3\) at will.</p></article></div>
E6 = (A-3*identity_matrix(6)).right_kernel(basis='pivot') E6
B = E6.basis() B
v = *B[0] + *B[1] v
%auto %html(hide=True) <div class="mathbook-content"><p id="p-6">We can check this. Compare \(Av\) with \(3v\text{.}\)</p></div>
A*v
3*v
%auto %html(hide=True) <div class="mathbook-content"><p id="p-7">Here's an easy check:</p></div>
A*v - 3*v
%auto %html(hide=True) <div class="mathbook-content"><p id="p-8">Can you make more eigenvectors?</p></div>
%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">Eigenspaces, Eigenmatrices</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-9">Continuing with <code class="code-inline tex2jax_ignore">A</code> from above, we can get eigen-stuff quickly from Sage, once we understand what is really happening (according to the definitions).</p></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-10">As always we want the “right” versions of the relevant commands. Eigenspaces are in the second parts of pairs, where the first part of each pair is the eigenvalue. Notice that they are vector spaces (with bases, etc). The basis vectors are Sage's version of a basis, with vectors from an echelonized matrix, typically with lots of zeros and ones in the first part of the vectors.</p></div>
A.eigenspaces_right()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-11">The <code class="code-inline tex2jax_ignore">eigenmatrix</code> commands return pair of matrices. The first is a diagonal matrix with the eigenvalues on the diagonal. The second is a square matrix with linearly independent eigenvectors in the columns, and the order of the eigenvectors is the same as the order of the eigenvalues. That is, the eigenvector in column <code class="code-inline tex2jax_ignore">i</code> of the second matrix is a basis vector for the eigenspace of the eigenvalue in column <code class="code-inline tex2jax_ignore">i</code> of the first matrix.</p></div>
A.eigenmatrix_right()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-12">Sometimes the dimension of an eigenspace (the geometric multiplicity) is strictly less than the number of times the eigenvalue appears as a root of the characteristic polynomial. This is the case with <code class="code-inline tex2jax_ignore">C</code> next, but was not the case with <code class="code-inline tex2jax_ignore">A</code> above.</p></div>
C = matrix(QQ, [ [128, 20, 44, -50, 236, -18, -330, -565], [ -23, -16, -5, 6, -40, 27, 62, 128], [ -44, -12, -15, 16, -78, 20, 110, 207], [ -2, 10, -4, 3, -10, -23, 20, -9], [ -61, 5, -25, 27, -116, -26, 153, 225], [ -12, -12, -1, 2, -20, 24, 34, 82], [ -23, -3, -8, 9, -42, 2, 57, 99], [ 13, 6, 3, -4, 23, -12, -35, -72] ]) C
C.eigenmatrix_right()
%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">Fancy Footwork</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-13">A totally random matrix is unlikely to have a characteristic polynomial that factors if we restrict ourseves to the rationals. But we can find all the roots over \(\overline{Q}\text{,}\) the set of all algebraic numbers. (This is the set of all real roots of all possible polynomials with integer coefficients.)</p></div>
D = random_matrix(QQ, 10) D
p = D.characteristic_polynomial() p.factor()
p.roots(ring=QQbar, multiplicities=False)
%auto %html(hide=True) <div class="mathbook-content"><p id="p-14">If we make a “block diagonal” matrix, then the characteristic polynomial will definitely factor some</p></div>
E = block_diagonal_matrix( [random_matrix(QQ, 5), random_matrix(QQ, 5)]) E
p = E.charpoly() p.factor()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-15">Finally a large example, illustrating how fast Sage is at making characteristic polynomials and at factoring.</p></div>
F = block_diagonal_matrix( [random_matrix(QQ, 50), random_matrix(QQ, 50)]) p = F.charpoly() p.factor()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-16">This is such a common operation, that Sage has a shorthand method for the <dfn class="terminology">Factored Characteristic Polynomial</dfn>, namely <code class="code-inline tex2jax_ignore">.fcp()</code>.</p></div>
F.fcp()
%auto %html(hide=True) <div class="mathbook-content"><p id="p-17">Nothing short of amazing!</p></div>
%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">Numerical Matrices</span> </h6></section></div>
%auto %html(hide=True) <div class="mathbook-content"><p id="p-18">If we use <code class="code-inline tex2jax_ignore">CDF</code> (Complex Double Field) for the number system of the entries of our matrix, we get (good) approximate values for eigenvalues. (If we are OK with the approximate nature, these routines are very, very fast.)</p></div>
G = random_matrix(QQ, 300) H = G.change_ring(CDF) H.eigenvalues()
%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-19">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>