Maxima can be useful

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:

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:

i-6460ad7ff77b35f8c7dd6f76b245810f-2010-07-13_la_te_xi_t_1.jpg

Now, to enter these two equations into Maxima:

i-d59e0e062dce1643636eb348fa446ef0-2010-07-13_terminal_lisp_80x24.jpg

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:

i-e582fb2f8e26b785c3897e95f151f203-2010-07-13_terminal_lisp_80x24_1.jpg

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.

i-7d34585b9557e58ad56ae06c91604e0d-2010-07-13_terminal_lisp_80x24_2.jpg

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-ea04162b27369c211605cba1f9830387-2010-07-13_terminal_lisp_80x24_3.jpg

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:

i-b2632b2ccc20cf8a334bd392417c514b-2010-07-13_terminal_lisp_80x24_4.jpg

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.

More like this

**pre-reqs:** [kinematics](http://scienceblogs.com/dotphysics/2008/09/basics-kinematics.php) My previous "basics" post was on kinematics (in one dimension). But what about two dimensions? In particular, what about projectile motion. My motivation here is that I was about to talk about analysis…
So, I've finally had some time to get back to the linear programming followup. You might want to go back and look at the earlier post to remember what I was talking about. The basic idea is that we've got a system we'd like to optimize. The constraints of the system are defined by a set of linear…
I am not a programmer. Just to be clear. I use python to get things done, but I am sure it could be done in more efficient ways. Anyway, I sure you know how much I like vpython - especially for teaching physics. However, sometimes I use it for blogging stuff also. The problem is that vpython…
Atwood's machine is the name of a device that looks like this: Also known as "two masses on a pulley". Surprisingly, this simple device comes up a lot in intro physics texts. It also brings up some interesting issues. I will go over the basic way to solve a problem like this (as an example) and…

maxima is quite handy - and wxmaxima puts a cleaner look onto the program.

%o7 doesn't give the expression twice; it gives two separate solutions - negative and positive.

By Lassi Hippeläinen (not verified) on 13 Jul 2010 #permalink

You got the expression twice in %o7 because you have to find the sqrt and negative sqrt of the equation (just like in the quadratic formula).

@wurmfood and @Lassi,

Wow - you are right. I didn't even see that. Thanks for pointing it out.

Rhett:

thanks for the post. i gotta remember all these physicsy tools you post about.

I've started using an app called Evernote (Evernote.com) for those bits of information that you will want at some undetermined point in the future.

Free app that will give you 20GB of storage per month. (No, I don't work for them.) Just like the app.

Definitely worth checking out.

JAZ

By JAZollars (not verified) on 13 Jul 2010 #permalink

Geez, I am so old that this computer algebra system looks like a real pain. I just retired from teaching math and physics for 35 years. The learning curve for students with these systems was pretty steep. We needed time in class to learn to use the systems. For high-school kids CAS was not a time-saver.

My good friend the low-pressure physics person loved Mathematica because he dealt with a lot of partial differential equations. (Low pressure was the field, not the attitude).

Different tools at different levels.

I don't know why Maxima's arrays don't use the normal use of [0] being the first element.

If by "normal" you mean "C-like" then the reason might be because mathematics doesn't work like C. Plenty of other languages work like mathematics.

"It's free and free and runs on Mac OS X and Windows."

While true, it's very incomplete. It also runs on Linux and BSD and Solaris and whatever else. (In fact, it's available in ubuntu's repositories so it's readily available for installation on Linux/Ubuntu.)

additionally, it's free, but it's also Free (as in freedom), being licensed under the GPL. This is important because then it's not just a black box that you have to Just Trust like maple, matlab, mathematica, etc. You can go in and figure out how it works, audit the code, perform static code analysis to make sure it's safe to embed in a web page, etc. (or have someone knowledgeable/trusted do it, and anyone you send a copy to must be granted the same license as you got it under.)

I'm a linux user, so the refrains of "We support *both* operating systems, Windows *and* Mac!" starts to get tiring after a while. ;)