SageMath

Trained as an electrical engineer, I am most comfortable with Matlab in terms of serving my math need. However, for symbolic math problems, Matlab is not as intuitive as Mathematica (of course, we can still do it though. Check out “syms”). But I never get used to the syntax of Mathematica. And I found the license requirement is quite annoying. Even though I got a legal license from the university I am affiliated with, I need to renew it manually every year. Actually, Matlab is beginning as annoying in recent years. I have to make sure my Internet is running well or my Matlab session will die eventually as it got disconnected from the license server of the university.

That is why unless absolutely necessary, I am often using the free alternatives instead. Octave is a great clone of Matlab. And it can be installed conveniently with just one “apt install” in Ubuntu:

sudo apt install octave

SageMath is not as a direct clone of Mathematica as Octave to Matlab. But as engineers love Octave, mathematicians seem to love SageMath. Again, it can be installed one line in Ubuntu (18.04 or above) with

sudo apt install sagemath

I found the syntax of SageMath much more intuitive to me than Mathematica since the former has more resemblance of numpy which I am more familiar with. And the Mathematica/jupyter-like notebook is definitely a plus comparing to Matlab/Octave.

Doing calculus is very simple. Say I want to find $latex \int (x+1) dx$.  I just need

var('x')  # indicate x is a symbolic variable
integral(x+1,x)

One can do definite integral without much changes also. For example, $latex \int_{x=1}^2 (x+1) dx$ translates to

var('x')
integral(x+1,x,1,2)

We can have the limits as symbols as well. For example, $latex \int_{x=a}^{a+b} (x+1) dx$ translates to

var('x','a','b')
integral(x+1,x,a,a+b)

Another function I used often is matrix operations. Say I like to compute $latex \begin{pmatrix} a & b \\ b & a \end{pmatrix} \begin{pmatrix} b & a \\ a & b\end{pmatrix}$. It simply translates to

var('a','b')
matrix( [[a,b],[b,a]])*matrix([[b,a],[a,b]])

 

Leave a Reply

Your email address will not be published. Required fields are marked *