2.4.2 Differentiation, Integration, etc.

Sage knows how to differentiate and integrate many functions. For example, to differentiate sin(u) with respect to u, do the following:

sage: u = var('u')
sage: diff(sin(u), u)
cos(u)

To compute the fourth derivative of sin(x2):

sage: diff(sin(x^2), x, 4)
16*x^4*sin(x^2) - 12*sin(x^2) - 48*x^2*cos(x^2)

To compute the partial derivatives of x2 + 17y2 with respect to x and y, respectively:

sage: x, y = var('x,y')
sage: f = x^2 + 17*y^2
sage: f.diff(x)
2*x
sage: f.diff(y)                                
34*y

We move on to integrals, both indefinite and definite. To compute the indefinite integral of x sin(x2) and the definite integral, as x goes from 0 to 1, of x/(x2 + 1):

sage: integral(x*sin(x^2), x)
-cos(x^2)/2
sage: integral(x/(x^2+1), x, 0, 1)
log(2)/2

To compute the partial fraction decomposition of 1/(x2-1):

sage: f = 1/((1+x)*(x-1))
sage: f.partial_fraction(x)
1/(2*(x - 1)) - 1/(2*(x + 1))
sage: print f.partial_fraction(x)
    1           1
--------- - ---------
2 (x - 1)   2 (x + 1)

See About this document... for information on suggesting changes.