Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168754
Image: ubuntu2004

Sage Calculus Commands

Tim McLarnan, Earlham College

 

Although our initial Introduction to Sage included discussion of a number of Sage functions related to calculus, you may not have noticed that fact if you didn't look carefully at what Sage can do. This handout is, in the first instance, just a summary of Sage's calculus-related functionality. As always, I'm only scratching the surface. The Sage help command (say derivative? to get help on derivative, for instance) offers a lot more information on any of the commands used in this Worksheet.

Basic Commands

Limits

Sage's command for limits is, logically enough, limit. Notice how Sage handles the limits below, distinguishing among infinite limits, undefined limits, and indeterminate limits for functions that are still locally bounded.  Notice, also that Sage gets one of these limits wrong.

 

var('x') limit(sin(x)/x, x=0)
\newcommand{\Bold}[1]{\mathbf{#1}}1
limit(1/x, x=0)
\newcommand{\Bold}[1]{\mathbf{#1}}+\infty
limit(1/x^2, x=0)
\newcommand{\Bold}[1]{\mathbf{#1}}+\infty
limit(sin(1/x), x=0)
\newcommand{\Bold}[1]{\mathbf{#1}}\mbox{ind}

Our investigation of derivatives could have been speeded up substantially had we been willing to use Sage uncritically as a black box for taking limits. Here, for instance, are calculations of the derivatives of the sine, exponential, and cube root functions. It would be useful review to try to remember how we obtained these results in class. Are you sure Sage doesn't have bugs that affect these calculations?

These calculation show an annoyance in Sage: In order to compute some limits, it needs to know whether various quantities are positive and whether they are integers, even though the result of the calculation doesn't depend on the answers to these questions.  We therefore end up having to use Sage's assume() function to give it various choices of sign and type for numbers.

var('h') limit((sin(x+h) - sin(x))/h, h=0)
\newcommand{\Bold}[1]{\mathbf{#1}}\cos\left(x\right)
limit((exp(x+h) - exp(x))/h, h=0)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_9.py", line 9, in <module> exec compile(ur'open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" + _support_.preparse_worksheet_cell(base64.b64decode("bGltaXQoKGV4cCh4K2gpIC0gZXhwKHgpKS9oLCBoPTAp"),globals())+"\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/private/var/folders/I0/I0BmI-fSGQeaVx+drmwZZU+++TM/-Tmp-/tmp7SC_WM/___code___.py", line 3, in <module> exec compile(ur'limit((exp(x+h) - exp(x))/h, h=_sage_const_0 )' + '\n', '', 'single') File "", line 1, in <module> File "/Applications/sage/local/lib/python2.6/site-packages/sage/calculus/calculus.py", line 1008, in limit l = ex._maxima_().limit(v, a) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1408, in __call__ return self._obj.parent().function_call(self._name, [self._obj] + list(args), kwds) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1316, in function_call return self.new(s) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1097, in new return self(code) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1032, in __call__ return cls(self, x, name=name) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1451, in __init__ raise TypeError, x TypeError: Computation failed since Maxima requested additional constraints (try the command 'assume(>0)' before integral or limit evaluation, for example): Is x an integer?
assume(x, 'integer') limit((exp(x+h) - exp(x))/h, h=0)
\newcommand{\Bold}[1]{\mathbf{#1}}e^{x}
forget() assume(x, 'noninteger') limit((exp(x+h) - exp(x))/h, h=0)
\newcommand{\Bold}[1]{\mathbf{#1}}e^{x}
forget()
var('a') limit((x^(1/3) - a^(1/3))/(x-a), x=a)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3 \, a^{\left(\frac{2}{3}\right)}}

Here's one last limit, just for fun.  You might think about how to do it by hand.

limit(x^x,x=0)
\newcommand{\Bold}[1]{\mathbf{#1}}1

Derivatives

Sage can also compute derivatives, either of expressions or of functions.  derivative(), differentiate(), and diff() are three different names for the same function (or method) for doing this.

nestrad = sqrt(x+sqrt(x+sqrt(x))) nestrad
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\sqrt{x + \sqrt{x + \sqrt{x
/span> }}}
diff(nestrad,x)
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(\frac{{\left(\frac{1}{\sqrt{x}} + 2\right)}}{\sqrt{x + \sqrt{x
+ 4\right)}}{8 \, \sqrt{x + \sqrt{x + \sqrt{x}}}} }}}
_.simplify_rational()
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(4 \, \sqrt{x + \sqrt{x}} \sqrt{x} + 2 \, \sqrt{x} + 1\right)}}{8 \, \sqrt{x + \sqrt{x}} \sqrt{x + \sqrt{x + \sqrt{x
\sqrt{x}} }}}
f(x)=x^x f
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ x^{x}
fprime = diff(f) fprime
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ {\left(\log\left(x\right) + 1\right)} x^{x}
pf = plot(f, (x,0,2), color='red') pfprime = plot(fprime, (x,0,2), color='blue') show(pf+pfprime,aspect_ratio=1, ymin=-2, ymax=2)
diff(sin(x),x)
\newcommand{\Bold}[1]{\mathbf{#1}}\cos\left(x\right)
diff(sin(x),x,4)
\newcommand{\Bold}[1]{\mathbf{#1}}\sin\left(x\right)
sin(x).diff(x,21)
\newcommand{\Bold}[1]{\mathbf{#1}}\cos\left(x\right)
f(x)=sin(x) diff(f)
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ \cos\left(x\right)
diff(f,x,4)
\newcommand{\Bold}[1]{\mathbf{#1}}x \ {\mapsto}\ \sin\left(x\right)
diff(f,x,4)(pi/4)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, \sqrt{2}

Sage can even handle differentiation rules for arbitrary functions, like this:

function('f g h') var('x')
\newcommand{\Bold}[1]{\mathbf{#1}}x
diff(f(x)*g(x),x)
\newcommand{\Bold}[1]{\mathbf{#1}}f\left(x\right) D[0]\left(g\right)\left(x\right) + g\left(x\right) D[0]\left(f\right)\left(x\right)
diff(f(x)/g(x), x)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{-f\left(x\right) D[0]\left(g\right)\left(x\right)}{g\left(x\right)^{2}} + \frac{D[0]\left(f\right)\left(x\right)}{g\left(x\right)}
diff(f(x)*g(x)*h(x),x)
\newcommand{\Bold}[1]{\mathbf{#1}}f\left(x\right) g\left(x\right) D[0]\left(h\right)\left(x\right) + f\left(x\right) h\left(x\right) D[0]\left(g\right)\left(x\right) + g\left(x\right) h\left(x\right) D[0]\left(f\right)\left(x\right)
diff(f(g(x)),x)
\newcommand{\Bold}[1]{\mathbf{#1}}D[0]\left(f\right)\left(g\left(x\right)\right) D[0]\left(g\right)\left(x\right)
diff(sqrt(f(x)),x)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{D[0]\left(f\right)\left(x\right)}{2 \, \sqrt{f\left(x\right)}}

Integrals

Sage can also compute integrals, naturally using the function (or method) integral().

integral(sin(x), x,0,pi)
\newcommand{\Bold}[1]{\mathbf{#1}}2
(1/x).integrate(x,1,e)
\newcommand{\Bold}[1]{\mathbf{#1}}1
integral(x/(1+x^2),x)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, \log\left(x^{2} + 1\right)
integral(x/(1+x^4),x)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, \arctan\left(x^{2}\right)

Big deal so far, but here's one I bet you can't do by hand, x1+x3dx\displaystyle\int\frac x{1+x^3}\,dx.

integral(x/(1+x^3),x)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, \sqrt{3} \arctan\left(\frac{1}{3} \, {\left(2 \, x - 1\right)} \sqrt{3}\right) - \frac{1}{3} \, \log\left(x + 1\right) + \frac{1}{6} \, \log\left(x^{2} - x + 1\right)
integral(x^3*e^x,x)
\newcommand{\Bold}[1]{\mathbf{#1}}{\left(x^{3} - 3 \, x^{2} + 6 \, x - 6\right)} e^{x}
var('n') integral(x^n,x)
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "_sage_input_39.py", line 9, in <module> exec compile(ur'open("___code___.py","w").write("# -*- coding: utf-8 -*-\n" + _support_.preparse_worksheet_cell(base64.b64decode("dmFyKCduJykKaW50ZWdyYWwoeF5uLHgp"),globals())+"\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in <module> File "/private/var/folders/I0/I0BmI-fSGQeaVx+drmwZZU+++TM/-Tmp-/tmpcccbuZ/___code___.py", line 3, in <module> exec compile(ur'integral(x**n,x)' + '\n', '', 'single') File "", line 1, in <module> File "/Applications/sage/local/lib/python2.6/site-packages/sage/misc/functional.py", line 716, in integral return x.integral(*args, **kwds) File "expression.pyx", line 7211, in sage.symbolic.expression.Expression.integral (sage/symbolic/expression.cpp:28877) File "/Applications/sage/local/lib/python2.6/site-packages/sage/symbolic/integration/integral.py", line 580, in integrate return indefinite_integral(expression, v) File "function.pyx", line 430, in sage.symbolic.function.Function.__call__ (sage/symbolic/function.cpp:4448) File "/Applications/sage/local/lib/python2.6/site-packages/sage/symbolic/integration/integral.py", line 85, in _eval_ res = integrator(f, x) File "/Applications/sage/local/lib/python2.6/site-packages/sage/symbolic/integration/external.py", line 18, in maxima_integrator result = expression._maxima_().integrate(v) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/maxima.py", line 2090, in integral return I(var) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1408, in __call__ return self._obj.parent().function_call(self._name, [self._obj] + list(args), kwds) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1316, in function_call return self.new(s) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1097, in new return self(code) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1032, in __call__ return cls(self, x, name=name) File "/Applications/sage/local/lib/python2.6/site-packages/sage/interfaces/expect.py", line 1451, in __init__ raise TypeError, x TypeError: Computation failed since Maxima requested additional constraints (try the command 'assume(n+1>0)' before integral or limit evaluation, for example): Is n+1 zero or nonzero?

Ah, this is good!  Sage should ask whether or not n=1n=-1.  After all, it makes a difference:

assume(n != -1) integral(x^n,x)
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{x^{{\left(n + 1\right)
{\left(n + 1\right)}} }}}
forget() assume(n == -1) integral(x^n,x)
\newcommand{\Bold}[1]{\mathbf{#1}}\log\left(x\right)

Sums

Sums were originally done in Sage with slightly unusual notation.  [1..10] means the list [1,2,3,4,5,6,7,8,9,10].  For convenience, range(n) is the list of integers xx such that 0x<n0\le x < n.  (Watch the endpoints here!)

range(5)
\newcommand{\Bold}[1]{\mathbf{#1}}\left[0, 1, 2, 3, 4\right]
sum(k^2 for k in [1..10])
\newcommand{\Bold}[1]{\mathbf{#1}}385

Sage now has a nicer notation for sums.

var('k') sum(k^2, k, 1, 10)
\newcommand{\Bold}[1]{\mathbf{#1}}385

Sage can also handle sums with variable or infinite endpoints.  Here's how to get Sage to compute the sums

$$

\sum_{k=1}^nk,\quad

\sum_{k=1}^nk^2,\quad

\sum_{k=1}^nk^3,\quad

\sum_{k=1}^\infty\frac1{k^2},\quad

\sum_{k=1}^\infty\frac1{k^4},\quad\text{and}\quad

\sum_{k=1}^\infty\frac1{k^3}.

$$

sum(k, k, 1, n)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{2} \, n^{2} + \frac{1}{2} \, n
sum(k^2, k, 1, n)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, n^{3} + \frac{1}{2} \, n^{2} + \frac{1}{6} \, n
sum(k^3, k, 1, n).factor()
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{4} \, {\left(n + 1\right)}^{2} n^{2}
sum(1/k^2, k, 1, infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{6} \, \pi^{2}
_.n()
\newcommand{\Bold}[1]{\mathbf{#1}}1.64493406684823
sum(1/k^4, k, 1, infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{90} \, \pi^{4}
sum(1/k^3, k, 1, infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}\zeta\left(3\right)
zeta(3).n()
\newcommand{\Bold}[1]{\mathbf{#1}}1.20205690315959

Sage can compute integrals using Riemann sums, though again, we have to use Maxima and we fall afoul of some problems with the Maxima interface.

The right hand Riemann sum for computing the integral

$$

\int_0^xt^3\,dt

$$

is

$$

\sum_{k=1}^n\left(\frac{kx}n\right)^3\cdot\frac xn,

$$

which Maxima can write and evaluate.

sum((k*x/n)^3*(x/n), k, 1, n)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(n^{2} + 2 \, n + 1\right)} x^{4}}{4 \, n^{2}}

We now want to take the limit of this as nn\to\infty in order to get the integral, right?

limit(_, n=infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{4} \, x^{4}

Bingo!  So

$$

\int_0^xt^3\,dt=\frac{x^4}4,

$$

just as we would have suspected.

More Complicated Tools

As one learns to work with Sage, one finds more and more ways to visualize and to work with the ideas of calculus.  Here, for instance, is a little interactive tool for illustrating the idea of the derivative of a function as the slope of the tangent line.  The blue curve is the function f(x)f(x), the dotted black curve is its derivative f(x)f'(x).  Moving the slider moves a point along the curve and the tangent line at that point.  As the tangent line moves, the green dot on the derivative curve traces out its slope.

var('x') f(x) = sin(x)*e^(-x) fp = f.diff() p = plot(f,-1,5, thickness=2) pp = plot(fp, -1, 5, color='black', linestyle=':') pt_list = (-0.4+0.1*j for j in range(45)) @interact def _(pt=pt_list): dot = point((pt,f(pt)),pointsize=80,rgbcolor='red') dotp = point((pt, fp(pt)), pointsize=80, rgbcolor='green') slope = fp(pt) sp = plot(f(pt)+slope*(x-pt),(x,-1, 5), color='green', thickness=2) html('<font color=red>Tangent to y = exp(-x)sin(x) at x = %s</font>'%pt) show(dot + dotp + p + pp + sp, ymin = -.5, ymax = 1)
forget()

And here are two functions for working with Riemann sums.  right_riemann_plot plots a curve and its right-hand Riemann sum, and right_riemann_value gives the value of this sum.

def right_riemann_plot(f, a, b, n): p = plot(f, a, b, thickness=2) deltax = (b-a)/n rectops = Piecewise([[(a+j*deltax, a+(j+1)*deltax),f(a+(j+1)*deltax)] for j in range(n)]) prectops = plot(rectops, color='green', fill='axis', fillcolor='green') outline = [] for j in range(n): outline = outline + [(a+j*deltax,0), (a+j*deltax,f(a+(j+1)*deltax)), (a+(j+1)*deltax,f(a+(j+1)*deltax)), (a+(j+1)*deltax, 0)] poutline = plot(line(outline, rgbcolor='black')) show(p + prectops + poutline)
def right_riemann_value(f, a, b, n): deltax = (b-a)/n return(sum(f(a+(j+1)*deltax)*deltax for j in range(n)))
right_riemann_plot(sin,0,pi,4)
right_riemann_value(sin,0,pi,4)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{4} \, \pi + \frac{1}{4} \, \pi \sqrt{2}
right_riemann_value(sin,0,pi,4).n()
\newcommand{\Bold}[1]{\mathbf{#1}}1.89611889793704
right_riemann_plot(sin,0,pi,25)
right_riemann_value(sin,0,pi,25).n()
\newcommand{\Bold}[1]{\mathbf{#1}}1.99736741254563
integral(sin(x),x,0,pi)
\newcommand{\Bold}[1]{\mathbf{#1}}2

Finally, here's a function for computing formal Riemann sums.  At least for simple functions, we end up with expressions where Sage can take the limit to evaluate the integral, though notice that occasionally Sage wants to do something more C\mathbb Complex than we think it should.

def right_riemann_sum(f,a,b,n): deltax = (b-a)/n return sum(f(a + k*deltax), k, 1, n)*deltax
right_riemann_sum(sin,0,1,3)
\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{1}{6} \, {\left({\left(-I \, e^{\left(\frac{1}{3} I\right)} + I \, e^{I} + I \, e^{\left(\frac{4}{3} I\right)} - I\right)} e^{I} - I \, e^{\left(\frac{2}{3} I\right)} + I \, e^{\left(\frac{8}{3} I\right)}\right)} e^{\left(-\frac{5}{3} I\right)}
right_riemann_sum(sin,0,1,3).n()
\newcommand{\Bold}[1]{\mathbf{#1}}0.595678494891262 - 9.71445146547012 \times 10^{-17}i
right_riemann_sum(sin,0,pi,4)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{4} \, {\left(\sqrt{2} + 1\right)} \pi
f(x)=x^2 right_riemann_sum(f,0,1,5)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{11}{25}
var('n') rs = right_riemann_sum(f,0,1,n) rs
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(2 \, n^{2} + 3 \, n + 1\right)}}{6 \, n^{2}}
limit(rs,n=infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3}
integral(f(x),x,0,1)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3}
var('z') rs = right_riemann_sum(f,1,z,n) rs
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(z - 1\right)} {\left({\left(2 \, n^{2} + 3 \, n + 1\right)} z^{2} + 2 \, {\left(n^{2} - 1\right)} z + 2 \, n^{2} - 3 \, n + 1\right)}}{6 \, n^{2}}
rs = rs.simplify_rational() rs
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left({\left(2 \, n^{2} + 3 \, n + 1\right)} z^{3} - 3 \, {\left(n + 1\right)} z^{2} - 3 \, {\left(n - 1\right)} z - 2 \, n^{2} + 3 \, n - 1\right)}}{6 \, n^{2}}
limit(rs, n=infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, z^{3} - \frac{1}{3}
integral(f(x),x,1,z)
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{3} \, z^{3} - \frac{1}{3}
rs = right_riemann_sum(exp,0,z,n) rs
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(e^{z} - 1\right)} z e^{\frac{z}{n
{\left(e^{\frac{z}{n}} - 1\right)} n} }}}
rs = rs.simplify_rational() rs
<html><span class="math">\newcommand{\Bold}[1]{\mathbf{#1}}\frac{{\left(z e^{z} - z\right)} e^{\frac{z}{n
{\left(n e^{\frac{z}{n}} - n\right)}} }}}
limit(rs, n=infinity)
\newcommand{\Bold}[1]{\mathbf{#1}}e^{z} - 1
integral(e^x,x,0,z)
\newcommand{\Bold}[1]{\mathbf{#1}}e^{z} - 1

Some Calculus Problems

As far as I can tell at this point, Sage doesn't have inert integrals like Maple, so some of the exercises in the Maple version of this worksheet which involve doing explicit changes of variable in inert integrals aren't so easy in Sage.  Others of our exercises from the Maple version are easy.  For instance, we can explicitly explore Taylor polynomials for the sine function by equating derivatives of sinxsin x with derivatives of a generic polynomial at x=0x=0, and we can then interactively plot the first few Taylor polynomials.

var('a0 a1 a2 a3 a4 a5') f(x) = a2*x^2 + a1*x + a0 s(x)=sin(x)
solve([f(0)==s(0),diff(f,x)(0)==diff(s,x)(0),diff(f,x,2)(0)==diff(s,x,2)(0)], a0,a1,a2)
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[a_{0} = 0, a_{1} = 1, a_{2} = 0\right]\right]
f(x) = a3*x^3 + a2*x^2 + a1*x + a0 solve([f(0)==s(0),diff(f,x)(0)==diff(s,x)(0),diff(f,x,2)(0)==diff(s,x,2)(0),diff(f,x,3)(0)==diff(s,x,3)(0)], a0,a1,a2,a3)
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[a_{0} = 0, a_{1} = 1, a_{2} = 0, a_{3} = \left(-\frac{1}{6}\right)\right]\right]
f(x) = a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0 solve(list(diff(f,x,k)(0)==diff(s,x,k)(0) for k in range(6)), a0,a1,a2,a3,a4,a5)
\newcommand{\Bold}[1]{\mathbf{#1}}\left[\left[a_{0} = 0, a_{1} = 1, a_{2} = 0, a_{3} = \left(-\frac{1}{6}\right), a_{4} = 0, a_{5} = \left(\frac{1}{120}\right)\right]\right]
@interact def _(terms=(j for j in range(17))): x = sage.calculus.calculus.var('x') sinplot = plot(sin(x), x,-18, 18, rgbcolor='blue') taypoly = sum((-1)^k*x^(2*k+1)/(2*k+1).factorial() for k in range(terms+1)) tayplot = plot(taypoly, x, -15,15, rgbcolor='red') html('<font color=red>y = sin(x) and its Maclaurin series of degree %s</font>'%(2*terms+1)) show(sinplot + tayplot, xmin=-18, xmax=18, ymin = -2, ymax = 2)