Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168738
Image: ubuntu2004
version()
'SAGE Version 3.1.2, Release Date: 2008-09-19'
x,y = var('x,y') @interact def _(f = input_box(default=y), g=input_box(default=-x*y+x^3-x), xmin=input_box(default=-1), xmax=input_box(default=1), ymin=input_box(default=-1), ymax=input_box(default=1), start_x=input_box(default=0.5), start_y=input_box(default=0.5), step_size=(0.01,(0.001, 0.2)), steps=(600,(0, 1400)) ): old_f = f f = f.function(x,y) old_g = g g = g.function(x,y) steps = int(steps) points = [ (start_x, start_y) ] for i in range(steps): xx, yy = points[-1] try: points.append( (xx+step_size*f(xx,yy), \ yy+step_size*g(xx,yy)) ) except (ValueError, ArithmeticError, TypeError): break starting_point = point(points[0], pointsize=50) solution = line(points) vector_field = plot_vector_field( (f,g), (x,xmin,xmax), \ (y,ymin,ymax) ) result = vector_field + starting_point + solution html(r"<h2>$ \frac{dx}{dt} = %s$ $ \frac{dy}{dt} = %s$</h2>"%(latex(old_f),latex(old_g))) print "Step size: %s"%step_size print "Steps: %s"%steps result.show(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax)
%sh cd ~ ls -la set ps -aux
WARNING: Output truncated!
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html total 200 drwxr-xr-x 5 sage29 sage29 4096 Sep 26 09:37 . drwxr-xr-x 38 root root 4096 Feb 14 2008 .. -rw-r--r-- 1 sage29 sage29 220 Jun 27 2007 .bash_logout -rw-r--r-- 1 sage29 sage29 414 Jun 27 2007 .bash_profile -rw-r--r-- 1 sage29 sage29 2227 Jun 27 2007 .bashrc -rw-r--r-- 1 sage29 sage29 27542 Jan 13 2008 .fonts.cache-1 drwxr-xr-x 2 sage29 sage29 4096 Sep 25 18:40 .matplotlib -rw------- 1 sage29 sage29 754 Feb 24 2008 .octave_hist drwx------ 6 sage29 sage29 4096 Oct 5 2007 .sage drwxr-xr-x 2 sage29 sage29 4096 Jun 27 2007 .ssh -rw-r--r-- 1 sage29 sage29 13639 Jul 11 15:11 maxout.gnuplot_pipes -rw-r--r-- 1 sage29 sage29 117771 Sep 25 19:17 maxout.openmath -rw-r--r-- 1 sage29 sage29 0 Sep 26 09:37 sageman AR=ar AS=as BASH=/bin/sh BASH_ARGC=() BASH_ARGV=() BASH_LINENO=([0]="0") BASH_SOURCE=([0]="/home/sage29/.sage//temp/sage/2765//tmp_12") BASH_VERSINFO=([0]="3" [1]="1" [2]="17" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu") BASH_VERSION='3.1.17(1)-release' CC=gcc CHMOD=chmod COLUMNS=80 CP=cp CUR=/home/sage29 CXX=g++ DIRSTACK=() DOT_SAGE=/home/sage29/.sage/ EUID=2061 GPDOCDIR=/home/server2/sage/local/share/pari/doc GPHELP=/home/server2/sage/local/bin/gphelp GP_DATA_DIR=/home/server2/sage/local/share/pari GROUPS=() HOME=/home/sage29 HOSTNAME=sage HOSTTYPE=x86_64 IFS=' ' LANG=en_US.UTF-8 LD=ld LDFLAGS= LD_LIBRARY_PATH=/home/server2/sage/local/lib/R/lib:/home/server2/sage/local/lib/openmpi:/home/server2/sage/local/lib/: LIBRARY_PATH=/home/server2/sage/local/lib/ LINES=24 LN=ln LOGNAME=sage29 MACHTYPE=x86_64-pc-linux-gnu MAIL=/var/mail/sage29 MAKE=make MATPLOTLIBRC=/home/sage29/.sage// MKDIR=mkdir MV=mv OLDPWD=/home/server2/sage_notebook/worksheets/semerikov/0/cells/2 OPTERR=1 OPTIND=1 ... sage21 2433 0.0 0.0 6380 1672 pts/162 S+ 09:24 0:00 bash /home/serv sage21 2445 0.1 0.1 402772 74972 pts/162 S+ 09:24 0:01 python -u sage20 2497 0.0 0.0 28248 17440 pts/127 Ss+ 09:25 0:00 /home/server2/s server2 2568 0.0 0.0 23692 2372 pts/31 SNs+ 09:28 0:00 /usr/bin/ssh -t root 2581 0.0 0.0 35676 2804 ? Ss 09:28 0:00 sshd: sage28 [p sage28 2592 0.0 0.0 35676 1680 ? S 09:28 0:00 sshd: sage28@pt sage28 2593 0.0 0.0 6248 1504 pts/142 Ss+ 09:28 0:00 bash -c ulimit sage28 2594 0.0 0.0 6260 1516 pts/142 S+ 09:28 0:00 bash /usr/local sage28 2597 0.0 0.0 6384 1680 pts/142 S+ 09:28 0:00 bash /home/serv sage28 2609 0.2 0.1 403040 75184 pts/142 S+ 09:28 0:01 python -u www-data 2674 0.0 0.0 95752 10400 ? SN 09:28 0:00 /usr/sbin/apach server2 2723 0.0 0.0 23692 2360 ? SN 09:32 0:00 ssh sage29@loca root 2725 0.0 0.0 35672 2756 ? Ss 09:32 0:00 sshd: sage29 [p server2 2724 0.0 0.0 23828 2464 pts/20 SNs+ 09:32 0:00 /usr/bin/ssh -t sage29 2728 0.0 0.0 35672 1632 ? S 09:32 0:00 sshd: sage29@no sage29 2729 0.0 0.0 6260 1512 ? Ss 09:32 0:00 bash /usr/local sage29 2732 0.0 0.0 6380 1672 ? S 09:32 0:00 bash /home/serv root 2744 0.0 0.0 35672 2800 ? Ss 09:32 0:00 sshd: sage29 [p sage29 2745 0.0 0.0 12332 3328 ? S 09:32 0:00 python /home/se sage29 2748 0.0 0.0 35808 1692 ? S 09:32 0:00 sshd: sage29@pt sage29 2749 0.0 0.0 6248 1508 pts/25 Ss+ 09:32 0:00 bash -c ulimit sage29 2750 0.0 0.0 6264 1516 pts/25 S+ 09:32 0:00 bash /usr/local sage29 2753 0.0 0.0 6384 1676 pts/25 S+ 09:32 0:00 bash /home/serv sage29 2765 3.5 0.1 409692 82136 pts/25 S+ 09:32 0:15 python -u sage29 2799 21.2 0.0 38148 27428 pts/134 Ss+ 09:32 1:29 /home/server2/s www-data 2859 0.0 0.0 92312 9100 ? SN 09:35 0:00 /usr/sbin/apach www-data 2861 0.0 0.0 92916 9016 ? SN 09:35 0:00 /usr/sbin/apach server2 2888 0.0 0.0 23692 2360 ? SN 09:36 0:00 ssh sage30@loca root 2890 0.0 0.0 35672 2760 ? Ss 09:36 0:00 sshd: sage30 [p server2 2889 0.0 0.0 23692 2372 pts/48 SNs+ 09:36 0:00 /usr/bin/ssh -t sage30 2893 0.0 0.0 35672 1636 ? S 09:36 0:00 sshd: sage30@no sage30 2894 0.0 0.0 6260 1512 ? Ss 09:36 0:00 bash /usr/local sage30 2897 0.0 0.0 6384 1680 ? S 09:36 0:00 bash /home/serv root 2898 0.0 0.0 35676 2804 ? Ss 09:36 0:00 sshd: sage30 [p sage30 2912 0.0 0.0 12328 3324 ? S 09:36 0:00 python /home/se sage30 2913 0.0 0.0 35676 1680 ? S 09:36 0:00 sshd: sage30@pt sage30 2914 0.0 0.0 6248 1508 pts/138 Ss+ 09:36 0:00 bash -c ulimit sage30 2915 0.0 0.0 6264 1520 pts/138 S+ 09:36 0:00 bash /usr/local sage30 2918 0.0 0.0 6384 1680 pts/138 S+ 09:36 0:00 bash /home/serv sage30 2930 0.7 0.1 402772 74972 pts/138 S+ 09:36 0:01 python -u www-data 2971 0.0 0.0 90080 7972 ? SN 09:36 0:00 /usr/sbin/apach www-data 2972 0.0 0.0 90092 7972 ? SN 09:36 0:00 /usr/sbin/apach www-data 2992 0.0 0.0 90184 8044 ? SN 09:37 0:00 /usr/sbin/apach www-data 2995 0.0 0.0 89948 7872 ? SN 09:37 0:00 /usr/sbin/apach www-data 3018 0.0 0.0 90092 7784 ? SN 09:38 0:00 /usr/sbin/apach www-data 3020 0.0 0.0 91652 8512 ? SN 09:38 0:00 /usr/sbin/apach www-data 3021 0.0 0.0 89948 7724 ? SN 09:38 0:00 /usr/sbin/apach www-data 3031 0.0 0.0 90088 7764 ? SN 09:38 0:00 /usr/sbin/apach www-data 3032 0.0 0.0 89948 7660 ? SN 09:38 0:00 /usr/sbin/apach www-data 3033 0.0 0.0 89948 7680 ? SN 09:38 0:00 /usr/sbin/apach www-data 3045 0.0 0.0 90088 7708 ? SN 09:39 0:00 /usr/sbin/apach www-data 3047 0.0 0.0 89948 7740 ? SN 09:39 0:00 /usr/sbin/apach www-data 3053 0.0 0.0 89948 7664 ? SN 09:39 0:00 /usr/sbin/apach www-data 3059 0.0 0.0 89948 7632 ? SN 09:39 0:00 /usr/sbin/apach www-data 3061 0.0 0.0 89948 7652 ? SN 09:39 0:00 /usr/sbin/apach www-data 3062 0.0 0.0 89816 6092 ? SN 09:39 0:00 /usr/sbin/apach sage29 3064 0.0 0.0 6276 1500 pts/25 S+ 09:39 0:00 sh -c chmod +x sage29 3066 0.0 0.0 6284 1216 pts/25 S+ 09:39 0:00 sh -c chmod +x sage29 3068 0.0 0.0 8416 948 pts/25 R+ 09:39 0:00 ps -aux /home/sage29
A = matrix([[1,1],[-1,1]]) D = [vector([0,0]), vector([1,0])] @interact def f(A = matrix([[1,1],[-1,1]]), D = '[[0,0],[1,0]]', \ k=(3..17)): print "Det = ", A.det() D = matrix(eval(D)).rows() def Dn(k): ans = [] for d in Tuples(D, k): s = sum(A^(-n)*d[n] for n in range(k)) ans.append(s) return ans G = points([v.list() for v in Dn(k)]) show(G, frame=True, axes=False)
var('x,y') @interact def example(clr=Color('orange'), f=4*x*exp(-x^2-y^2), xrange='(-2, 2)', yrange='(-2,2)', zrot=(0,pi), xrot=(0,pi), zoom=(1,(1/2,3)), square_aspect=('Square Frame', False), tachyon=('Ray Tracer', True)): xmin, xmax = sage_eval(xrange); ymin, ymax = sage_eval(yrange) P = plot3d(f, (x, xmin, xmax), (y, ymin, ymax), color=clr) html('<h1>Plot of $f(x,y) = %s$</h1>'%latex(f)) aspect_ratio = [1,1,1] if square_aspect else [1,1,1/2] show(P.rotate((0,0,1), -zrot).rotate((1,0,0),xrot), viewer='tachyon' if tachyon else 'jmol', figsize=6, zoom=zoom, frame=False, frame_aspect_ratio=aspect_ratio)
var('x') @interact def midpoint(n = slider(1,100,1,4), f = input_box(default = \ "x^2", type = str), start = input_box(default = "0", type = \ str), end = input_box(default = "1", type = str)): a = N(start) b = N(end) func = sage_eval(f, locals={'x':x}) dx = (b-a)/n midxs = [q*dx+dx/2 + a for q in range(n)] midys = [func(x_val) for x_val in midxs] rects = Graphics() for q in range(n): xm = midxs[q] ym = midys[q] rects = rects + line([[xm-dx/2,0],[xm-dx/2,ym], \ [xm+dx/2,ym], [xm+dx/2,0]], rgbcolor=(1,0,0)) + point((xm,ym), \ rgbcolor = (1,0,0)) min_y = find_minimum_on_interval(func,a,b)[0] max_y = find_maximum_on_interval(func,a,b)[0] html('<h3>Numerical integrals with the midpoint rule</h3>') html('$\int_{a}^{b}{f(x) dx} {\\approx} \sum_i{f(x_i) \Delta x}$') print "\n\nSage numerical answer: " + \ str(integral_numerical(func,a,b,max_points = 200)[0]) print "Midpoint estimated answer: " + \ str(RDF(dx*sum([midys[q] for q in range(n)]))) show(plot(func,a,b) + rects, xmin = a, xmax = b, ymin = \ min_y, ymax = max_y)
x = var('x') @interact def _(f=sin(x), g=cos(x), xrange=input_box((0,1)), yrange='auto', a=1, action=selector(['f', 'df/dx', 'int f', 'num f', 'den f', '1/f', 'finv', 'f+a', 'f-a', 'f*a', 'f/a', 'f^a', 'f(x+a)', 'f(x*a)', 'f+g', 'f-g', 'f*g', 'f/g', 'f(g)'], width=15, nrows=5, label="h = "), do_plot = ("Draw Plots", True)): try: f = SR(f); g = SR(g); a = SR(a) except TypeError, msg: print msg[-200:] print "Unable to make sense of f,g, or a as symbolic expressions." return if not (isinstance(xrange, tuple) and len(xrange) == 2): xrange = (0,1) h = 0; lbl = '' if action == 'f': h = f lbl = 'f' elif action == 'df/dx': h = f.derivative(x) lbl = '\\frac{df}{dx}' elif action == 'int f': h = f.integrate(x) lbl = '\\int f dx' elif action == 'num f': h = f.numerator() lbl = '\\text{numer(f)}' elif action == 'den f': h = f.denominator() lbl = '\\text{denom(f)}' elif action == '1/f': h = 1/f lbl = '\\frac{1}{f}' elif action == 'finv': h = solve(f == var('y'), x)[0].rhs() lbl = 'f^{-1}(y)' elif action == 'f+a': h = f+a lbl = 'f + a' elif action == 'f-a': h = f-a lbl = 'f - a' elif action == 'f*a': h = f*a lbl = 'f \\times a' elif action == 'f/a': h = f/a lbl = '\\frac{f}{a}' elif action == 'f^a': h = f^a lbl = 'f^a' elif action == 'f^a': h = f^a lbl = 'f^a' elif action == 'f(x+a)': h = f(x+a) lbl = 'f(x+a)' elif action == 'f(x*a)': h = f(x*a) lbl = 'f(xa)' elif action == 'f+g': h = f+g lbl = 'f + g' elif action == 'f-g': h = f-g lbl = 'f - g' elif action == 'f*g': h = f*g lbl = 'f \\times g' elif action == 'f/g': h = f/g lbl = '\\frac{f}{g}' elif action == 'f(g)': h = f(g) lbl = 'f(g)' html('<center><font color="red">$f = %s$</font></center>'%latex(f)) html('<center><font color="green">$g = %s$</font></center>'%latex(g)) html('<center><font color="blue"><b>$h = %s = %s$</b></font></center>'%(lbl, latex(h))) if do_plot: P = plot(f, xrange, color='red', thickness=2) + \ plot(g, xrange, color='green', thickness=2) + \ plot(h, xrange, color='blue', thickness=2) if yrange == 'auto': show(P, xmin=xrange[0], xmax=xrange[1]) else: yrange = sage_eval(yrange) show(P, xmin=xrange[0], xmax=xrange[1], ymin=yrange[0], ymax=yrange[1])