All published worksheets from http://sagenb.org
Image: ubuntu2004
A brief tutorial for calculus on Sage
Sage is a free open-source mathematics software system. It is quite powerful, and can be used for a wide range of mathematical tasks, but today we'll focus on the basics of using Sage to do integration. First, we'll look at the basics of communicating with Sage.
Using Sage as a calculator
Try typing 2+2 into the box below. Hit Shift+Enter or click "evaluate" to evaluate. (See what happens if you just hit Enter. I guarantee this will happen to you many times. It happens to me often when I use Sage.)
Sage knows about mathematical constants, like and . It also knows a lot of commonly used functions, such as the natural log, trig functions, and inverse trig functions. Try evaluating each of the following.
Notice that by default, Sage will not give a numerical answer if it can give a symbolic answer. This is usually good - you can keep symbolic expressions in your work until the very end, so that you minimize rounding errors. Sometimes it might not simplify as much as you'd like. Every expression has a numerical approximation method and a simplify method. An method of an expression is invoked by using the "." operator (a period). The numerical approximation method is n() and the simplify method is simplify(). Evaluate the examples below.
Use Sage to compute
- a decimal value of 55/6 (Hint: 55/6 is an expression and has an n() method, too.)
- the cosine of
- the natural log of 123
Variables and expressions
In order to use a variable like to define an expression in Sage, you have to tell Sage that you want to use that symbol as a variable. You can use expressions to define equations, which Sage can solve. Evaluate the following to see how this works.
We can use Sage to find the quadratic formula. Sage will solve an expression in multiple variables for one in terms of all the others.
In Sage a 'callable symbolic expression' is a mathematical epression using a variable you have defined. The following examples will illustrate how you can work with these.
You can plot these functions pretty easily.
Plot more than one function by adding plots. You can also play around with colors and ranges.
Try these:
- Define a function in terms of : . Evaluate your function at and .
- plot
- Solve an equation in the variable to find out where the graphs of and intersect. Make a plot showing the intersection points.
Actual Calculus
Sage can also find derivatives and integrals (definite and indefinite) of expressions. (Note that the integral function returns an antiderivative.)
You can also take derivatives and integrals of expressions directly. Here we find the derivative and antiderivative of the function .
Incidentally, check this out:
Remember, Sage can do lots of stuff symbolically. For example, consider the function . We can easily find an expression for this function, and then compute with it.
Note that Sage confirms the Fundamental Theorem of Calculus:
Some exercises
Now you should have enough Sage tools to answer some questions.
1. Compute
2. Last time we worked hard to integrate .
- Check our work from last time using Sage.
- Note also that Sage expressions have a partial_fraction() method, which will try to compute a partial fraction decomposition. Experiment with this to find the partial fraction decomposition.
3. Let be the length of the parabola from to , where is a constant. Write an integral for , and use Sage to evaluate this integral to produce a function. Plot it.
4. Plot the on the interval . Use Sage to see whether the regions above and below the axis generate equal volumes when rotated about the axis.