Skip to main content

Section B.1 Basics

Basic computations.

Use the Evaluate button below the Sage cell to try it out.

Creating and evaluating a function.

If you want to use a variable other than x in your expressions, you need to tell Sage about it.

Constants and standard functions.

Sage knows about all the usual constants and functions. Careful, Sage uses I as the imaginary number.

Referring to previous results.

You can use an underscore to refer to the previous output, two underscores to refer to the output from two commands ago, and three underscores to refer to the output from three commands ago. (I think that's as far as it goes, but give it a try.)

Here, the “previous” output will be from the last cell that computes I^2 above.

Working with objects.

Sage treats everything as a Python object, so you can apply methods to them.

Notice that Sage didn't actually output anything for the initial assignment of the expression in the variable x to the variable a. If you want confirmation of your input, use the print command. (If you are using a Sage command line installed locally on your computer, you can just type the variable and hit enter without the print part.)

Other things you might want to do with polynomial objects:

Evaluating numerical results to a decimal number.

Use the n() method to evaluate to a decimal number.