Contrary to what some of my friends might think, I’ve been really sympathetic to the arguments against Mathematica that talk about how it’s not Free and Open Source Software (FOSS). I’m always happy to see what my friends and colleagues produce with FOSS to solve/model/teach/learn physics problems. Python and VPython are used quite a bit, and I’m also really interested in Sage, which puts together lots of FOSS tools in one package.
But, as I think about moving myself off of Mathematica towards those tools, there are a few things that hold me up. I thought I’d post about them to see if others could help me out.
1. Less syntax for ODEs
I really like the NDSolve command in Mathematica. You give it the differential equation you want to numerically solve, along with any initial/boundary conditions. You tell it the independent and dependent variables (and their limits) and hit go. With that, you get an interpolation function that can be plotted, integrated, analyzed, and on and on. Whenever I see my friends doing similar work in python, I’m often struck by how much code is necessary to accomplish what NDSolve can do in one line.
Of course, I understand and value the arguments that a) students should know what the code is doing, and b) you can always make your own functions to make it easier to repeat. My (admittedly weak) counter argument comes from the amount of time I’ve spent teaching students how to do this. If we can get to investigating some cool physics problems faster, I’m usually happy to ignore those two good arguments.
2. Combining analytic and numeric results
This one has stopped me in my tracks often as I think about transitioning my Theoretical Mechanics class away from Mathematica. This is such a powerful feature of Mathematica, that I treat it like a crutch I feel I can’t do without. It comes down to how Mathematica treats everything in the same manner, so that you can take derivatives of things you wouldn’t normally think of, for example.
Here’s my prototypical example. Let’s say you want to model a complex mechanical system using a Lagrangian approach. Students learn that they need to identify what the relevant variables are, and then they need to construct the kinetic and potential energy of the system. Once you have those, you can construct the Lagrangian (L=Kinetic – Potential) and you can obtain the governing equations of motion via the Euler-Lagrange equation:
where q and represent a particular variable and its time derivative. You’d have lots of those equations if you have lots of variables.
Here’s how I’d do a simple mass on a spring (no gravity) in Mathematica to determine the equation of motion:
m=1; k=100; T=1/2 m x'[t]^2; (* kinetic energy *) U=1/2 k x[t]^2; (* potential energy *) L=T-U; (* Lagrangian *) eom=D[L,x[t]]-D[L,x'[t],t]==0; (* equation of motion *)
I would then put that equation of motion into NDSolve. Now, this is a simple example, and you can do much more complicated things this way. My point is that the derivatives I’m taking in the “L” line are actually kind of complicated. They’re taken with respect to x[t], in one case, and x'[t], in another. I’ve looked around on the Sage forums for how to do similar things, and I’ve been pretty intimidated by the suggested methods. If people could help me figure this out in Python or Sage, I’d be very motivated to try to switch my spring class over.
So, yes, it’s true, I’m actually asking this: Please help me try to wean myself off of Mathematica. I’m not sure whether I can really do it, especially given my facility with it, but I think it would be cool if I could accomplish my teaching/research/fun goals with software that didn’t cost so much. I’m certainly willing to put in the time to learn new syntax, but these two points have really held me back.
Oh yeah, one more thing, you’re free to rub this all in my face if you like (you know who you are).