The other day I found myself faced with six equations that needed to be solved algebraically. Just so you know, I am a big fan of paper for most of these cases – but this was out of control. I was making silly mistakes and causing all sorts of problems. What to do? My first though was to use some symbolic plugins for python. I tried sympy and it is nice. However, it was not giving correct solutions for solving 3 equations – I don’t know if this is a bug or what.
Maxima
I think I found Maxima through Wikipedia’s Computer algebra system page. It’s free and free and runs on Mac OS X and Windows.
The point of this post is not just to tell you about this software, really it is to tell me about it. I probably won’t use this for a while, and so I will forget what I did. First, some useful resources:
- Introduction to Maxima. This intro by Richard Rand is very thorough. Basically, it has everything you need.
- How to export your equation in LaTeX. This is something I found that seemed quite useful.
So, if you want to get a good start, look at the intro link above. But I will summarize a couple of quick things. First, entering expressions. One thing I did not like about sympy was that expressions were entered as 2x + y = 0 instead of 2x = -y. In Maxima, just enter the equation. Here are some rules:
- Use normal order of operations stuff
- Don’t forget * for multiplication. If you do 2x, you will get an error. 2*x is ok.
- You can use variables that are longer than 1 character, but it can’t start with a number – x2 is ok, but not the variable 2x.
- When you enter a statement, you must end with a “;”
- The output of every entry is labeled something like – %o19. This is nice because you can refer to this output in later entries.
An Example
Let me show a simple example. I will use two of the kinematic equations to create a third kinematic equations – algebraically. Let me start with:
Now, to enter these two equations into Maxima:
Notice that you use normal (non-python) format for entering expressions – by non-python I mean that the “^” means raised to the power instead of “**”. The output is formatted in a way to look a little nicer.
Now, I want to solve the second equation for t:
Here, I referred to the original equation by its output line number (%o3 in this case where that is an “o”, not a zero). Next, I just want to substitute this expression for t into the first equation.
The command in line %i6 may look weird. But this is saying take the equation %o2 (which is the first equation) and substitute t = … (which is equation %o5). Now I want to take this equation and solve for v2 – so that it is in its usual form.
I don’t know why it gave the expression twice. Update: As pointed out in the comments below, this is because there are two answers, a positive and a negative. End update If you just wanted 1 answer, you could type %o7[1]; – I don’t know why Maxima’s arrays don’t use the normal use of [0] being the first element.
Finally, if you want to get this as v2^2:
That is good enough to get some useful stuff done. Also, hello to future me. I am probably going to find this post 3 months from now when I forget how to do something in Maxima.