Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Views: 16658

Math 152: Intro to Mathematical Software

2017-01-27

Kiran Kedlaya; University of California, San Diego

adapted from lectures by William Stein, University of Washington

** Lecture 8: Symbolic Calculus (part 1) **

Announcements:

Usual schedule next week! (including sections, office hours, homework, peer evaluation)

%md ## Some Resources for Symbolic Calculus in Sage - Basic Sage Calculus Tutorial: http://www.sagemath.org/calctut/ - Sage for Undergraduates: http://www.gregorybard.com/Sage.html - Sage reference manual: http://doc.sagemath.org/html/en/reference/calculus/index.html - Sage Calculus "thematic tutorial": http://doc.sagemath.org/html/en/prep/Calculus.html

Some Resources for Symbolic Calculus in Sage

%md ## Short crash course - defining symbolic variables - defining symbolic functions - plot - differente - integrate - finding zeros

Short crash course

  • defining symbolic variables

  • defining symbolic functions

  • plot

  • differente

  • integrate

  • finding zeros

reset()
x*x
x^2
y + theta
Error in lines 1-1 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> NameError: name 'y' is not defined
# x is predefined; can define other variables... %var y, theta, aleph, xi
<type 'sage.symbolic.expression.Expression'>
show(x+y+theta +aleph+xi) type(y)
aleph+θ+x+ξ+y\displaystyle \mathit{aleph} + \theta + x + \xi + y
<type 'sage.symbolic.expression.Expression'>
var('y, theta')
(y, theta)
f(z, william) = z*(z+1)*william f()
william*(z + 1)*z
z + william
william + z
type(william)
<type 'sage.symbolic.expression.Expression'>
type(f)
<type 'sage.symbolic.expression.Expression'>
f.parent()
Callable function ring with arguments (z, william)
f - f
(z, 0
show(f)
(z,william)  william(z+1)z\displaystyle \left( z, \mathit{william} \right) \ {\mapsto} \ \mathit{william} {\left(z + 1\right)} z
# GOTCHA! z = .5 f(z) = z*(z+1) # this line whacks the previous defn of z!! print f() print z
(z + 1)*z
typpe(z)
<type 'sage.symbolic.expression.Expression'>
<type 'sage.symbolic.expression.Expression'>
z = .5 def f(z): print z f(1) print z
1 0.500000000000000
f(z) = z*(z+1) g = plot(f, (0, 3), color='chartreuse', thickness=10ess=10, ) # has a bazillion options show(g + text('hi there class!', (2,6), , zorder=))
diff(x^5 + 2*x + pi, x) diff(tan(x)^2, x)
2*(tan(x)^2 + 1)*tan(x) cos(x)
f = sin(x)*cos(x)*tan(x) g = integrate(f, x) show(g)
12x14sin(2x)\displaystyle \frac{1}{2} \, x - \frac{1}{4} \, \sin\left(2 \, x\right)
h = g.differentiate(x) show(h)
k = h - f show(k)
cos(x)sin(x)tan(x)12cos(2x)+12\displaystyle -\cos\left(x\right) \sin\left(x\right) \tan\left(x\right) - \frac{1}{2} \, \cos\left(2 \, x\right) + \frac{1}{2}
k
-cos(x)*sin(x)*tan(x) - 1/2*cos(2*x) + 1/2
k.simplify_trig()
0
k.simplify_full()
0
sin(x).find_root(-5,5)
0.0
N(sin(1/2), digits=50)
0.47942553860420300027328793521557138808180336794060
complex_plot(x, (-1,1), (-1,1)) complex_plot(x^2^2, (-1,1), (-1,1))
f(x) = 1/sqrt(1-xx^4) g = e(f,x) diff(g,x)
x |--> 1/sqrt(-x^4 + 1)
plot(g)
Error in lines 1-1 Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 554, in wrapper return func(*args, **options) File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1931, in plot G = funcs.plot(*args, **original_opts) File "sage/symbolic/expression.pyx", line 11386, in sage.symbolic.expression.Expression.plot (/projects/sage/sage-7.5/src/build/cythonized/sage/symbolic/expression.cpp:63509) return plot(f, *args, **kwds) File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 554, in wrapper return func(*args, **options) File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1946, in plot G = _plot(funcs, (xmin, xmax), **kwds) File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/plot/plot.py", line 2257, in _plot randomize) File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/plot/plot.py", line 3871, in generate_plot_points data[i] = (float(xj), float(f(xj))) File "sage/ext/interpreters/wrapper_py.pyx", line 68, in sage.ext.interpreters.wrapper_py.Wrapper_py.__call__ (/projects/sage/sage-7.5/src/build/cythonized/sage/ext/interpreters/wrapper_py.c:1800) raise File "sage/ext/interpreters/wrapper_py.pyx", line 60, in sage.ext.interpreters.wrapper_py.Wrapper_py.__call__ (/projects/sage/sage-7.5/src/build/cythonized/sage/ext/interpreters/wrapper_py.c:1734) return interp_py((<PyTupleObject*>args).ob_item File "sage/symbolic/function.pyx", line 996, in sage.symbolic.function.BuiltinFunction.__call__ (/projects/sage/sage-7.5/src/build/cythonized/sage/symbolic/function.cpp:11436) res = super(BuiltinFunction, self).__call__( File "sage/symbolic/function.pyx", line 491, in sage.symbolic.function.Function.__call__ (/projects/sage/sage-7.5/src/build/cythonized/sage/symbolic/function.cpp:6580) res = g_function_eval2(self._serial, (<Expression>args[0])._gobj, File "/projects/sage/sage-7.5/local/lib/python2.7/site-packages/sage/symbolic/integration/integral.py", line 78, in _eval_ if len(x.variables()) == 1: AttributeError: 'float' object has no attribute 'variables'
(z)