<?xml version="1.0" encoding="UTF-8" ?><?xml-stylesheet type="text/xsl" href="sagenb.xsl"?><!-- xsltproc -X-stringparam "purpose" "worksheet" sagenb.xsl uvic-part1.xml > uvic-part1.nb --><worksheet>    <headerinfo><title>Workshop: Getting Started with Sage</title><author>Robert A. Beezer</author><affiliation>University of Puget Sound</affiliation><event>Kansas City Regional Mathematics Technology Expo</event><date>October 6, 2012</date></headerinfo><section><title>Account Creation, Public Servers</title><p><ol><li>Need an OpenID account (GMail, Yahoo!, etc.)</li><li>Passwords/Security is OK, but not super-robust.</li><li>"New Worksheet" link/button in upper-left.</li><li>Retitle to anything you want.</li></ol></p></section><section><title>Making a Plot</title><p><ol><li>Click inside a cell - border changes, "evaluate" button appears</li><li>Type: <code> plot(x^3, (x, -2, 2)) </code></li><li>Hit "evaluate"</li><li>Want a new cell?  Hover until you see a <b>blue bar</b> and click on it.</li><li>Congratulations: You can now use Sage from any computer with a connection and browser!</li></ol></p></section><section><title>Algebra and Calculus</title><subsection><title>Expressions versus Functions</title><p>Sage has variables + symbolic expressions AND functions.  They look the same, but are different.</p><p>The variable <code>x</code> is predefined, everything else must be declared.</p>   <sage><in>var('a b')expand((2*a+b)^4)</in></sage><sage><in>expression = 91125*a^9 + 346275*a^8*b - 95985*a^7*b^2 - 1849527*a^6*b^3 - 1535976*a^5*b^4 + 2893680*a^4*b^5 + 4382720*a^3*b^6 - 456960*a^2*b^7 - 3311616*a*b^8 - 1404928*b^9factor(expression)</in></sage></subsection><subsection><title>Equation Solving</title><sage><in>slns = solve(2*x^2 + 9*x - 35 == 0, x)slns    </in></sage><sage><in>slns[0]</in></sage><p>We want the right hand side.</p><sage><in>slns[0].rhs()</in></sage><p>An alternative:</p><sage><in>solve(2*x^2 + 9*x - 35 == 0, x, solution_dict=True)</in></sage><p>How would we know about this alternative?  Immediate help on <code>solve()</code>. (Question-mark, then the TAB key.)</p><sage><in>solve?</in></sage></subsection><subsection><title>Functions and Calculus</title><p>Notice how a function prints differently than an expression.</p><sage><in>f(x) = e^-x - xf    </in></sage><p>Evaluation (exact, approximate), graphing, differentiation, integration.  Note object-oriented syntax.</p><sage><in>f(4)</in></sage><sage><in>f(4).n(digits=15)</in></sage><sage><in>f.plot(f, -2, 2)</in></sage><sage><in>f.diff()</in></sage><sage><in>f.integral(x)</in></sage><p>Question: How would we learn about these <q>methods</q>?<br />Answer: "Tab-completion" on <code>f</code>.  f-dot-tab</p><sage><in>f.</in></sage></subsection></section><section><title>Linear Algebra</title><p>Suppose you know <em>nothing</em> about how to do linear algebra in Sage.  (Maybe this is not a difficult supposition!)</p><p>If you can make a matrix and a vector, then you are off and running. Here they are, with entries from the field of rational numbers.</p>   <sage><in>A = matrix(QQ, [[1,2,3], [4,5,6]])A    </in></sage><sage><in>v = vector(QQ, [7, 8, 9])</in></sage><p>Then tab-completion and ?-tab-help will get you up to speed quickly.</p>   <sage><in>A.</in></sage><sage><in>v.</in></sage><p>And the <a href="http://wiki.sagemath.org/quickref">Sage Quick Reference</a> sheets ("quickrefs") are very handy.</p></section><section><title>Getting Help</title><p>There is lots of documentation.  The "Reference Manual" is about 4000 pages as a PDF and not organized for a beginner.  The "Tutorial" has some fairly advanced mathematics in it.  The "PREP Tutorials" are new and a great way to get started.</p><p><ul><li><q>Help</q> link in upper-right corner gives a pop-up window</li><li><q>Tutorial</q>, <q>Thematic Tutorials</q>, <q>Constructions</q>, <q>Reference Manual</q></li><li>Highly recommended:  <a href="http://www.sagemath.org/doc/prep/index.html">MAA PREP Workshop Tutorials</a></li></ul></p></section><section><title>Moving Worksheets Around</title><p><ul><li><q>File</q> drop-down box - <q>Save worksheet to a file...</q> makes a <code>*.sws</code> file</li><li><q>Upload</q> link/button - provide URL or Browse to local file to pull in a worksheet</li><li><q>Publish</q> on a server</li><li><q>Share</q> on a server</li><li>Warning: accounts do not span multiple servers</li><li>Students can share to a single-purpose class account to submit work</li></ul></p><p><br />Upload Now: <code>http://buzzard.ups.edu/kcexpo.sws</code><br /></p></section><section><title>An Exercise</title><p>Try the following exercise, with minimal guidance.<br /><br /></p><p>Theorem (from Algebraic Graph Theory):<br />The number of walks of length \(k\), between vertices \(u\) and \(v\) of a graph, is the \((u,v)\) entry of \(A^k\), where \(A\) is the adjacency matrix of the graph.<br /><br /></p><p>Question: How many walks are there of length \(7\) between two vertices of the complete bipartite graph \(K_{6,9}\) that lie in different <q>halves</q> of the bipartition?<br /><br /></p><p>1. Build the complete bipartite graph \(K_{6,9}\), whose edges join every vertex of a \(6\)-set to every vertex of a \(9\)-set.  Save this graph as the variable <code>G</code>.  Plot a picture of the graph. (Hint:  try out <code><![CDATA[graphs.<tab>]]></code>)</p><sage><in></in></sage><sage><in></in></sage><p>2. Construct and save the adjacency matrix of the graph as the variable <code>A</code>.</p><sage><in></in></sage><p>3. Construct and save the seventh power of the adjacency matrix of the graph as the variable <code>B</code>.</p><sage><in></in></sage><p>4. Output the entry of <code>B</code> that corresponds to two vertices from different <q>halves</q> of the bipartition.  (Hint:  use your picture to decide which vertices to use.  Matrix indexing starts counting from <code>0</code> and brackets, (<code>[, ]</code>), are used to index into a matrix.)</p><sage><in></in></sage><p><br /><br /><br /><br />Did you get \(6^3\,9^3 = 157\,464\) walks of length \(7\)?  How about walks of length \(8\) between the same two vertices?</p><sage><in></in></sage><p>Extra credit: write a one-line statement to get the answer.</p><p>Extra, extra credit: write a Python function that accepts a graph \(G\), and values of \(k\), \(u\), \(v\) as input and returns the number of walks.</p></section><section><title>Links</title>    <p>This worksheet available at: <a href="http://buzzard.ups.edu/talks.html">http://buzzard.ups.edu/talks.html</a></p></section></worksheet>