Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168703
Image: ubuntu2004

Sage can do symbolic calculus, which makes differentiation and integration a snap. It uses Mathematica syntax, which you may recognize from Wolfram Alpha. The general form for differentiation is:

diff(function, variable to differentiate with respect to, which derivative to take)

For example, to take the third derivative of log(x+1), we write:

l=log(x+1) d=diff(log(x+1),x,3)
2/(x + 1)^3
L=plot(l,rgbcolor=(0,0.5,0)) D=plot(d,rgbcolor=(0.5,0,0)) title=text('log(x+1) and its 3rd derivative',(-0.6,1)) dlabel=text('2/(x+1)^3',(-0.7,-0.5),rgbcolor=(0,0.5,0)) llabel=text('log(x+1)',(0.5,0.9),rgbcolor=(0.5,0,0)) g=L+D+title+dlabel+llabel g.show(xmin=-1,xmax=1,ymin=-1,ymax=1)

We can also do partial derivatives.  First we have to specify what in our expression are variables. There are two ways to do this.  The first is to explicitly declare the variables first.

x,y,z=var('x y z') diff(sin(x)+x*cos(y)+tan(z),y,2)
-x*cos(y)

The second method is to turn our expression into a function of several variables.

f(a,b,c)=a^2+2*b+a/c diff(f,c)
(a, b, c) |--> -a/c^2

Here is yet another way to do the same thing, this time taking the 2nd derivative with respect to c:

a,b,c=var('a b c') f=a^2+2*b+a/c fprimec=f.diff(c,2)
2*a/c^3