Last Updated 10/28/2022

Sage Essentials
Section 2: Algebraic Calculations

In this section you will learn how to enter an algebraic expression and substitute values in for the variables. Then you will learn the commands that allow you to expand, factor and simplify expressions.

The .sub command

Example 1

Let us look at how to substitute values into an algebraic expression. Suppose you want to evaluate the expression w=x2 +x+1 where x has the value 4.

Note that if our expression is in t instead of x, the codes above do not work. Try it!

By default, the only variable Sage can recognize is x. All other variables need to be derived from existing variables (w is derived as a varaible in the first example) or defined.

To define t as a variable, we insert an additional declaration command.

Try this! Set up the formula for the area A of a circle with radius r. Then use the formula to calculate the value of A for r=1 and r=2.


← Previous Example Next Example →