Linear Algebra -- Thematic Tutorials v4.7.rc0
system:sage


<div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index" accesskey="I">index</a></li>
  
    
      <a href="../../index.html"><img src="../_static/sagelogo.png" style="vertical-align: middle" title="Sage Logo"></a>
    
  
  
        <li><a href="../index.html">Thematic Tutorials v4.7.rc0</a> &raquo;</li>
 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="linear-algebra">
<span id="siena-tutorials-worksheet06-linearalgebra"></span><h1>Linear Algebra<a class="headerlink" href="#linear-algebra" title="Permalink to this headline">¶</a></h1>
<p><em>Author: Franco Saliola &lt;saliola at gmail.com&gt;</em></p>
<div class="section" id="vectors">
<h2>Vectors<a class="headerlink" href="#vectors" title="Permalink to this headline">¶</a></h2>
<p>To create a vector in Sage, use the  <tt class="docutils literal"><span class="pre">vector</span></tt>  command.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">vectors in Sage are <em>row</em> vectors!</p>
</div>
<p><strong>Exercises</strong></p>
<ol class="arabic">
<li><p class="first">Create the vector <img class="math" src="../_images/math/5dd335fe2281bff2720734bd40ff199e74313b9f.png" alt="x = (1, 2, \ldots, 100)">.</p>
<div class="highlight-python">

{{{id=0|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Create the vector <img class="math" src="../_images/math/cb019b6cc891d356a366cc0465b3c14389ae1d94.png" alt="y = (1^2, 2^2, \ldots, 100^2)">.</p>
<div class="highlight-python">

{{{id=1|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Type <tt class="docutils literal"><span class="pre">x.</span></tt> and hit tab to see the available methods for vectors. Find the
<em>norm</em> (length) of the vectors <tt class="docutils literal"><span class="pre">x</span></tt> and <tt class="docutils literal"><span class="pre">y</span></tt>.</p>
<div class="highlight-python">

{{{id=2|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Find the  <em>dot product</em>  of  <tt class="docutils literal"><span class="pre">x</span></tt>  and  <tt class="docutils literal"><span class="pre">y</span></tt> .</p>
<div class="highlight-python">

{{{id=3|
# edit here
///
}}}

</div>
</li>
</ol>
<p>[The above exercises are essentially the first problem on Exercise Set 1 of  <a class="reference external" href="http://modular.math.washington.edu/">William Stein&#8217;s</a>   <a class="reference external" href="http://wiki.wstein.org/09/480b">Math 480b</a>]</p>
</div>
<div class="section" id="matrices">
<h2>Matrices<a class="headerlink" href="#matrices" title="Permalink to this headline">¶</a></h2>
<ol class="arabic">
<li><p class="first">Use the  <tt class="docutils literal"><span class="pre">matrix</span></tt>  command to create the following matrix over the
rational numbers (hint: in Sage,  <tt class="docutils literal"><span class="pre">QQ</span></tt>  denotes the field of rational
numbers).</p>
<div class="math">
<p><img src="../_images/math/4c2ff8a2882f107ddd6d80dba8a852905a12fbba.png" alt="\left(\begin{array}{rrrrrr}3 & 2 & 2 & 1 & 1 & 0 \\2 & 3 & 1 & 0 & 2 & 1 \\2 & 1 & 3 & 2 & 0 & 1 \\1 & 0 & 2 & 3 & 1 & 2 \\1 & 2 & 0 & 1 & 3 & 2 \\0 & 1 & 1 & 2 & 2 & 3\end{array}\right)"></p>
</div><ol class="loweralpha">
<li><p class="first">Find the  <em>echelon form</em>  of the above matrix.</p>
<div class="highlight-python">

{{{id=4|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Find the  <em>right kernel</em>  of the matrix.</p>
<div class="highlight-python">

{{{id=5|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Find the  <em>eigenvalues</em>  of the matrix.</p>
<div class="highlight-python">

{{{id=6|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Find the  <em>left eigenvectors</em>  of the matrix.</p>
<div class="highlight-python">

{{{id=7|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Find the  <em>right eigenspaces</em>  of the matrix.</p>
<div class="highlight-python">

{{{id=8|
# edit here
///
}}}

</div>
</li>
</ol>
</li>
<li><p class="first">For what values of <img class="math" src="../_images/math/8c325612684d41304b9751c175df7bcc0f61f64f.png" alt="k"> is the  <em>determinant</em>  of the following matrix
<img class="math" src="../_images/math/bc1f9d9bf8a1b606a4188b5ce9a2af1809e27a89.png" alt="0">?</p>
<div class="math">
<p><img src="../_images/math/2d2d105b9f4fe0b454593dfc155c9f59ee4ab668.png" alt="\left(\begin{array}{rrr}1 & 1 & -1 \\2 & 3 & k \\1 & k & 3\end{array}\right)"></p>
</div><div class="highlight-python">

{{{id=9|
# edit here
///
}}}

</div>
<p>[K. R. Matthews,  <a class="reference external" href="http://www.numbertheory.org/book/">Elementary Linear Algebra</a> , Chapter 4, Problem 8]</p>
</li>
<li><p class="first">Prove that the determinant of the following matrix is <img class="math" src="../_images/math/922c4f40c55a550006c796efcd63a7828ecfd95f.png" alt="-8">.</p>
<div class="math">
<p><img src="../_images/math/e42451ea9cebdec3117cf132522e1129dfceb990.png" alt="\left(\begin{array}{rrr}{n}^{2}  & {\left( n + 1 \right)}^{2}  & {\left( n + 2\right)}^{2}  \\{\left( n + 1 \right)}^{2}  & {\left( n + 2 \right)}^{2}  &{\left( n + 3 \right)}^{2}  \\{\left( n + 2 \right)}^{2}  & {\left( n + 3 \right)}^{2}  & {\left( n + 4 \right)}^{2}\end{array}\right)"></p>
</div><div class="highlight-python">

{{{id=10|
# edit here
///
}}}

</div>
<p>[K. R. Matthews,  <a class="reference external" href="http://www.numbertheory.org/book/">Elementary Linear Algebra</a> , Chapter 4, Problem 3]</p>
</li>
<li><p class="first">Prove that if <img class="math" src="../_images/math/72e83f34256cb7ea48304c1a2354f30973256e3e.png" alt="a \neq c">, then the line through the points
<img class="math" src="../_images/math/8e8da0aef2d19017da7471378386d61620f288f5.png" alt="(a,b)"> and <img class="math" src="../_images/math/79e31171b9eaf222673b566ed3cf773e0f0b532c.png" alt="(c,d)"> is given by the following equation.</p>
<div class="math">
<p><img src="../_images/math/46737406bcfa2d0f07529dd9ff0010b65234c501.png" alt="\det\left(\begin{array}{rrr}x & y & 1 \\a & b & 1 \\c & d & 1\end{array}\right) = 0."></p>
</div><div class="highlight-python">

{{{id=11|
# edit here
///
}}}

</div>
</li>
<li><p class="first">Find the determinant of the following matrices.</p>
<div class="math">
<p><img src="../_images/math/308588b05d7ab694b480d64ed8855e12e0e66a70.png" alt="\left(\begin{array}{r}1\end{array}\right),\left(\begin{array}{rr}1 & 1 \\r & 1\end{array}\right),\left(\begin{array}{rrr}1 & 1 & 1 \\r & 1 & 1 \\r & r & 1\end{array}\right),\left(\begin{array}{rrrr}1 & 1 & 1 & 1 \\r & 1 & 1 & 1 \\r & r & 1 & 1 \\r & r & r & 1\end{array}\right),\left(\begin{array}{rrrrr}1 & 1 & 1 & 1 & 1 \\r & 1 & 1 & 1 & 1 \\r & r & 1 & 1 & 1 \\r & r & r & 1 & 1 \\r & r & r & r & 1\end{array}\right)"></p>
</div><p>Make a conjecture about the determinant of an arbitrary matrix in this
sequence. Can you prove it your conjecture?</p>
<div class="highlight-python">

{{{id=12|
# edit here
///
}}}

</div>
<p>[Adapted from: K. R. Matthews,  <a class="reference external" href="http://www.numbertheory.org/book/">Elementary Linear Algebra</a> , Chapter 4, Problem 19]</p>
</li>
<li><p class="first">What is the largest determinant possible for a <img class="math" src="../_images/math/77d7104f34af16053b63ce7cfa87265d915c6105.png" alt="3\times3"> matrix whose
entries are <img class="math" src="../_images/math/dc86b1470f75e97d70fb5146a46a7e1c0e4d6236.png" alt="1, 2, \dots, 9"> (each occurring exactly once, in any
order). How many matrices <img class="math" src="../_images/math/5d1e4485dc90c450e8c76826516c1b2ccb8fce16.png" alt="M"> achieve this maximum?</p>
<p>(<em>Hint:</em>  You might find the command  <tt class="docutils literal"><span class="pre">Permutations</span></tt>  useful. The
following code will construct all the lists that have the entries <img class="math" src="../_images/math/745b4cc1e9ebfd00b3d294e8ffa57a37ebcac799.png" alt="1,
2, 3, 4">, each appearing exactly once.)</p>
<div class="highlight-python"><div class="highlight"><pre>for P in Permutations(4):
    L = list(P)
    print L
</pre></div></div>
<div class="highlight-python">

{{{id=13|
for P in Permutations(4):
       L = list(P)
       print L
///
[1, 2, 3, 4]
[1, 2, 4, 3]
[1, 3, 2, 4]
[1, 3, 4, 2]
[1, 4, 2, 3]
[1, 4, 3, 2]
[2, 1, 3, 4]
[2, 1, 4, 3]
[2, 3, 1, 4]
[2, 3, 4, 1]
[2, 4, 1, 3]
[2, 4, 3, 1]
[3, 1, 2, 4]
[3, 1, 4, 2]
[3, 2, 1, 4]
[3, 2, 4, 1]
[3, 4, 1, 2]
[3, 4, 2, 1]
[4, 1, 2, 3]
[4, 1, 3, 2]
[4, 2, 1, 3]
[4, 2, 3, 1]
[4, 3, 1, 2]
[4, 3, 2, 1]
}}}

</div>
<div class="highlight-python">

{{{id=14|
# edit here
///
}}}

</div>
</li>
</ol>
</div>
<div class="section" id="id3">
<h2><a class="reference external" href="http://projecteuler.net/index.php?section=problems&id=11">Project Euler Problem 11</a><a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>In the <img class="math" src="../_images/math/da6211b23811ccc9872b8a2083d169d5c36859c4.png" alt="20 \times 20"> grid below, four numbers along a diagonal line have
been highlighted.</p>
<blockquote>
<div class="line-block">
<div class="line">08  02  22  97  38  15  00  40   00   75   04   05   07  78  52  12  50  77  91  08</div>
<div class="line">49  49  99  40  17  81  18  57   60   87   17   40   98  43  69  48  04  56  62  00</div>
<div class="line">81  49  31  73  55  79  14  29   93   71   40   67   53  88  30  03  49  13  36  65</div>
<div class="line">52  70  95  23  04  60  11  42   69   24   68   56   01  32  56  71  37  02  36  91</div>
<div class="line">22  31  16  71  51  67  63  89   41   92   36   54   22  40  40  28  66  33  13  80</div>
<div class="line">24  47  32  60  99  03  45  02   44   75   33   53   78  36  84  20  35  17  12  50</div>
<div class="line">32  98  81  28  64  23  67  10 <strong>26</strong> 38   40   67   59  54  70  66  18  38  64  70</div>
<div class="line">67  26  20  68  02  62  12  20   95 <strong>63</strong> 94   39   63  08  40  91  66  49  94  21</div>
<div class="line">24  55  58  05  66  73  99  26   97   17 <strong>78</strong> 78   96  83  14  88  34  89  63  72</div>
<div class="line">21  36  23  09  75  00  76  44   20   45   35 <strong>14</strong> 00  61  33  97  34  31  33  95</div>
<div class="line">78  17  53  28  22  75  31  67   15   94   03   80   04  62  16  14  09  53  56  92</div>
<div class="line">16  39  05  42  96  35  31  47   55   58   88   24   00  17  54  24  36  29  85  57</div>
<div class="line">86  56  00  48  35  71  89  07   05   44   44   37   44  60  21  58  51  54  17  58</div>
<div class="line">19  80  81  68  05  94  47  69   28   73   92   13   86  52  17  77  04  89  55  40</div>
<div class="line">04  52  08  83  97  35  99  16   07   97   57   32   16  26  26  79  33  27  98  66</div>
<div class="line">88  36  68  87  57  62  20  72   03   46   33   67   46  55  12  32  63  93  53  69</div>
<div class="line">04  42  16  73  38  25  39  11   24   94   72   18   08  46  29  32  40  62  76  36</div>
<div class="line">20  69  36  41  72  30  23  88   34   62   99   69   82  67  59  85  74  04  36  16</div>
<div class="line">20  73  35  29  78  31  90  01   74   31   49   71   48  86  81  16  23  57  05  54</div>
<div class="line">01  70  54  71  83  51  54  69   16   92   33   48   61  43  52  01  89  19  67  48</div>
</div>
</blockquote>
<p>The product of these numbers is <img class="math" src="../_images/math/3f22402d4bb070c6029b656daf764de2684489e6.png" alt="26 \times 63 \times 78 \times 14 =
1788696">.</p>
<p>What is the greatest product of four adjacent numbers in any direction (up,
down, left, right, or diagonally) in the <img class="math" src="../_images/math/da6211b23811ccc9872b8a2083d169d5c36859c4.png" alt="20 \times 20"> grid?</p>
<div class="highlight-python">

{{{id=15|
A = matrix(20, 20, [
      8, 2,22,97,38,15, 0,40, 0,75, 4, 5, 7,78,52,12,50,77,91, 8,
      49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48, 4,56,62, 0,
      81,49,31,73,55,79,14,29,93,71,40,67,53,88,30, 3,49,13,36,65,
      52,70,95,23, 4,60,11,42,69,24,68,56, 1,32,56,71,37, 2,36,91,
      22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80,
      24,47,32,60,99, 3,45, 2,44,75,33,53,78,36,84,20,35,17,12,50,
      32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70,
      67,26,20,68, 2,62,12,20,95,63,94,39,63, 8,40,91,66,49,94,21,
      24,55,58, 5,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72,
      21,36,23, 9,75, 0,76,44,20,45,35,14, 0,61,33,97,34,31,33,95,
      78,17,53,28,22,75,31,67,15,94, 3,80, 4,62,16,14, 9,53,56,92,
      16,39, 5,42,96,35,31,47,55,58,88,24, 0,17,54,24,36,29,85,57,
      86,56, 0,48,35,71,89, 7, 5,44,44,37,44,60,21,58,51,54,17,58,
      19,80,81,68, 5,94,47,69,28,73,92,13,86,52,17,77, 4,89,55,40,
      4,52, 8,83,97,35,99,16, 7,97,57,32,16,26,26,79,33,27,98,66,
      88,36,68,87,57,62,20,72, 3,46,33,67,46,55,12,32,63,93,53,69,
      4,42,16,73,38,25,39,11,24,94,72,18, 8,46,29,32,40,62,76,36,
      20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74, 4,36,16,
      20,73,35,29,78,31,90, 1,74,31,49,71,48,86,81,16,23,57, 5,54,
      1,70,54,71,83,51,54,69,16,92,33,48,61,43,52, 1,89,19,67,48
      ])
///
}}}

</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference internal" href="#">Linear Algebra</a><ul>
<li><a class="reference internal" href="#vectors">Vectors</a></li>
<li><a class="reference internal" href="#matrices">Matrices</a></li>
<li><a class="reference internal" href="#id3">Project Euler Problem 11</a></li>
</ul>
</li>
</ul>

            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/siena_tutorials/Worksheet06-LinearAlgebra.txt" rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index">index</a></li>
  
    
      <a href="../../index.html"><img src="../_static/sagelogo.png" style="vertical-align: middle" title="Sage Logo"></a>
    
  
  
        <li><a href="../index.html">Thematic Tutorials v4.7.rc0</a> &raquo;</li>
 
      </ul>
    </div>
    
    <div class="footer">
        &copy; Copyright 2005--2011, The Sage Development Team.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.4.
    </div>
    <script type="text/javascript">
/*global jQuery, window */
/* Sphinx sidebar toggle.  Putting this code at the end of the body
 * enables the toggle for the live, static, and offline docs.  Note:
 * sage.misc.html.math_parse() eats jQuery's dollar-sign shortcut. */
var jq = jQuery;  
jq(document).ready(function () {
    var bar, bod, bg, fg, key, tog, wid_old, wid_new, resize, get_state, set_state;
    bod = jq('div.bodywrapper');
    bar = jq('div.sphinxsidebar');
    tog = jq('<div class="sphinxsidebartoggle"></div>');
    
    /* Delayed resize helper.  Not perfect but good enough. */
    resize = function () {
        setTimeout(function () {
            tog.height(bod.height());
        }, 100);
    };
    jq(window).resize(function () {
        resize();
    });
    
    /* Setup and add the toggle. See Sphinx v0.5.1 default.css. */
    fg = jq('div.sphinxsidebar p a').css('color') || 'rgb(152, 219, 204)';
    bg = jq('div.document').css('background-color') || 'rgb(28, 78, 99)';
    wid_old = '230px';
    wid_new = '5px';
    tog.css('background-color', bg)
        .css('border-width', '0px')
        .css('border-right', wid_new + ' ridge ' + bg)
        .css('cursor', 'pointer')
        .css('position', 'absolute')
        .css('left', '-' + wid_new)
        .css('top', '0px')
        .css('width', wid_new);
    bod.css('position', 'relative');
    bod.prepend(tog);
    resize();
    
    /* Cookie helpers. */
    key = 'sphinxsidebar=';
    set_state = function (s) {
        var date = new Date();
        /* Expiry in 7 days. */
        date.setTime(date.getTime() + (7 * 24 * 3600 * 1000));
        document.cookie = key + encodeURIComponent(s) + '; expires=' +
            date.toUTCString() + '; path=/';
    };
    get_state = function () {
        var i, c, crumbs = document.cookie.split(';');
        for (i = 0; i < crumbs.length; i += 1) {
            c = crumbs[i].replace(/^\s+/, '');
            if (c.indexOf(key) === 0) {
                return decodeURIComponent(c.substring(key.length, c.length));
            }
        }
        return null;
    };
    
    /* Event handlers. */
    tog.mouseover(function (ev) {
        tog.css('border-right-color', fg);
    }).mouseout(function (ev) {
        tog.css('border-right-color', bg);
    }).click(function (ev) {
        if (bod.hasClass('wide')) {
            bod.removeClass('wide');
            bod.css('margin-left', wid_old);
            bar.css('width', wid_old);
            bar.show();
            set_state('visible');
        } else {
            set_state('hidden');
            bar.hide();
            bar.css('width', '0px');
            bod.css('margin-left', wid_new);
            bod.addClass('wide');
        }
        resize();
    });
    
    /* Hide the normally visible sidebar? */
    if (get_state() === 'hidden') {
        tog.trigger('click');
    } else {
        set_state('visible');
    }
});
    </script>