Sage Quick Reference

Run a file:

Create matrices:

Solve M * X = Y (where M – co-efficients; Y – constants) :

Create variables (symbolic math):

Algebra using Sage

Here are some examples of Sage used as a Computer algebra system.

Define the symbols x and y using var. Then define r2 in terms of x and y as per the Pythagorean theorem.

The output remains in terms of x and y:

This works with trigonometry…


…and matrices too. Below is an example of a matrix to translate and rotate a point in two dimensions.


Sage also does differentiation and integration but I am still trying to wrap my head around those two concepts.

Solve set of equations using Sage

Given the set of equations:

\( \begin{bmatrix} 5 & 0 & 0 \\ 0 & 10 & 0 \\ 0 & 0 & 15 \end{bmatrix} \times \left[ \begin{array}{c} x_1 \\ x_2 \\ x_3 \end{array} \right] = \left[ \begin{array}{c} 1 \\ 2 \\ 3 \end{array} \right] \)

Below is how to solve them using Sage:

The output:

In order to get the output as floating point numbers use the numerical_approx function:

The output: