How To Do Some Calculus in Sage
How To Do Some Calculus in Sage
These examples are from the Sage Tutorial and the Sage Constructions.
I suggest that you download the Tutorial as a PDF, since the partial differentiation
symbols, and other symbols, do not show up on the web version (even in Firefox).
The Constructions are not available (as of 4/23/08) as a PDF, but only on-line.
To compute
d sin(x2) /dx4 :
4
sage: diff(sin(x^2), x, 4)
16*x^4*sin(x^2) - 12*sin(x^2) - 48*x^2*cos(x^2)
Notice the syntax:
diff (function, var wrt you are differentiating, how many times)
To compute, (x2+17y2)/ x, (x2+17y2)/ y
sage: x, y = var(x,y)
The line above tells Sage that you have variables x and y
sage: f = x^2 + 17*y^2
The line above defines the function
sage: f.diff(x)
2*x
sage: f.diff(y)
34*y
Notice the syntax for differentiating f with respect to x or y.
To compute x sin(x2) dx, 01 x/(x2+1) dx:
sage: integral(x*sin(x^2), x)
-cos(x^2)/2
sage: integral(x/(x^2+1), x, 0, 1)
log(2)/2
Notice the syntax. The integral operator takes either 2 parameters for an
indefinite integral or 4 for a definite integral.
Notes:
1. latex(any expression) will give you the LaTeX version of that expression.
2. You can use Sages interface to Maxima for solving ODEs
http://www.sagemath.org/doc/html/const/node11.html
The Tutorial (section 2.10) has examples using Laplace transforms and
iteration.