MAA Talk on Sage

William Stein

February 26, 2011,   Santa Rosa

{{{id=110| /// }}} {{{id=99| /// }}}

Factor

Factoring an integer:

{{{id=1| factor(2012) /// \newcommand{\Bold}[1]{\mathbf{#1}}2^{2} \cdot 503 }}}

Factoring a symbolic expression:

{{{id=8| var('x,y') factor(x^8 - y^2*e^(2*x)) /// \newcommand{\Bold}[1]{\mathbf{#1}}{\left(x^{4} - y e^{x}\right)} {\left(x^{4} + y e^{x}\right)} }}} {{{id=6| /// }}} {{{id=98| /// }}} {{{id=97| /// }}} {{{id=96| /// }}} {{{id=95| /// }}} {{{id=94| /// }}}

Graph Theory

{{{id=76| set_random_seed(1); G = graphs.RandomLobster(7, .6, .3); show(G) /// }}} {{{id=77| G.automorphism_group() /// \newcommand{\Bold}[1]{\mathbf{#1}}\langle (11,23)(24,25) \rangle }}} {{{id=78| graph_editor(G) ///
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{} }}} {{{id=79| G.is_planar() /// \newcommand{\Bold}[1]{\mathbf{#1}}{\rm True} }}} {{{id=103| /// }}} {{{id=102| /// }}} {{{id=101| /// }}} {{{id=20| /// }}}

Symbolic Integrals

{{{id=88| integrate(sin(x)*tan(x), x) /// \newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{2} \, \log\left(\sin\left(x\right) - 1\right) + \frac{1}{2} \, \log\left(\sin\left(x\right) + 1\right) - \sin\left(x\right) }}} {{{id=19| f = 1/sqrt(x^2 + 2*x - 1) f.integrate(x) /// \newcommand{\Bold}[1]{\mathbf{#1}}\log\left(2 \, x + 2 \, \sqrt{x^{2} + 2 \, x - 1} + 2\right) }}} {{{id=18| /// }}} {{{id=26| /// }}} {{{id=93| /// }}} {{{id=92| /// }}} {{{id=91| /// }}} {{{id=90| /// }}}

Plotting Functions

{{{id=71| plot(sin(x^2), (x,0,5)) /// }}} {{{id=27| var('x') @interact def h(f=sin(x^2), grid=True, t=(1..20)): show(plot(f, (x, 0, 3), thickness=t, color='purple', fill=True, gridlines=grid)) ///
grid 
}}} {{{id=106| /// }}} {{{id=105| /// }}} {{{id=104| /// }}} {{{id=32| /// }}}

Plotting a Function in 3D

{{{id=30| f(x,y) = sin(x - y)*y*cos(x) plot3d(f, (x,-3,3), (y,-3,3), opacity=.7, color='red') + icosahedron(color='blue') /// }}}

An implicit 3D plot:

{{{id=89| T = RDF(golden_ratio) var('x,y,z') p = (2 - (cos(x + T*y) + cos(x - T*y) + cos(y + T*z) + cos(y - T*z) + cos(z - T*x) + cos(z + T*x))) r = 4.77 implicit_plot3d(p, (x, -r, r), (y, -r, r), (z, -r, r), plot_points=40) /// }}} {{{id=65| /// }}} {{{id=64| /// }}}

Image Compression

{{{id=29| import pylab; import numpy A_image = numpy.mean(pylab.imread(DATA + 'santarosa.png'), 2) u,s,v = numpy.linalg.svd(A_image); S = numpy.zeros( A_image.shape ) S[:len(s),:len(s)] = numpy.diag(s) n = A_image.shape[0] @interact def svd_image(i = ("Eigenvalues (quality)",(20,(1..A_image.shape[0]//2)))): A_approx = numpy.dot(numpy.dot(u[:,:i], S[:i,:i]), v[:i,:]) g = graphics_array([matrix_plot(A_approx), matrix_plot(A_image)]) show(g, axes=False, figsize=(10,6)) html("Compressed to %.1f%% of size using %s eigenvalues."%( 100*(2.0*i*n+i)/(n*n), i)) ///
Eigenvalues (quality) 
}}} {{{id=82| /// }}} {{{id=81| /// }}} {{{id=49| /// }}} {{{id=112| /// }}}