Skip to content

Using SageMath

K Clough edited this page Sep 11, 2023 · 11 revisions

SageMath is an open source, python based software for doing symbolic algebra, analysis and many other abstract and numerical mathematical operations, as an alternative to closed source applications like Maple, Mathematica and Matlab. It is slightly more limited in its functionality, but it has the advantage of an open source community, and because its code is open source, you can really understand how and what it is doing, unlike something like Mathematica where you cannot see what it is doing "beneath the hood" because it is proprietary.

SageMath is run in notebooks very like Jupyter ones, but requires additional packages to be installed for them to work. These packages cannot be installed on our lab computers, as they require a linux based operating system. If you are using the lab computers you will therefore need to use the online method described below.

Using SageMath if you have Windows or are using the Campus machines

We will use CoCalc to run SageMath notebooks where needed. You should set up a (free) profile there so that you can save things and come back to your projects.

Set up a project (maybe named MTH739), and add a SageMath notebook (similar to a Jupyter notebook, but with more functionality). If you get stuck, a ChatGPT prompt is built in to help you!

In the SageMath notebook prompt type

u = var('u')
diff(sin(u), u)

And shift-enter to execute. This should return cos(u), showing that it is working correctly.

Now upload the example SageMath notebook from the Week 1 materials to CoCalc and execute the cells, just to get an idea of how it works and what it can do.

Using SageMath if you have installed Anaconda on your linux/Mac/WSL machine

You should have previously added conda-forge using:

conda config --add channels conda-forge

Now install sage by doing:

conda install sage

You can either do this in your virtual environment, or just do a general install on your machine if you think SageMath will be something you use frequently. Further details can be found here, but you should not need them.

Once installed, try to open a sagemath jupyter notebook using the terminal command

sage -jupyter notebook

Create a new SageMath notebook (click on New in the top right of the jupyter notebook interface, and select a SageMath notebook). In the prompt type

u = var('u')
diff(sin(u), u)

And shift-enter to execute. This should return cos(u), showing that it is working correctly.

Now download the example SageMath notebook from the Week 1 materials and execute the cells, just to get an idea of how it works and what it can do.

Clone this wiki locally