Yesterday, I gave a short, five-minute talk (with accompanying paper, see [1]) on applying Python and its symbolic computational library SymPy [2] to solving very simple kinematics problems in the discipline of mechanics. The takeaway is that calculus problems aren’t hard [3], but rather tedious. Rudimentary integrals that can be broken down to dozens, sometimes even hundreds, of arithmetical operations. This is unacceptable, and scientists may turn to scientific computing to make their lives easier.

The Task at Hand [4]

I’ll give you the TL; DR version, if you want, you can read the paper for more a somewhat more detailed discussion. Basically we have this hypothetical non-constant acceleration function:

We are interested in working out its displacement function, that is, the mathematical function that describes its motion. We compute a double integral to work out displacement, or…

Working out its displacement shouldn’t be too hard with Python. First, we import all modules from SymPy:

>>> from sympy import *

Next, we define the function and its constants…

>>> b,c,d,v_i,x_i,t = symbols(b c d v_i x_i t)
>>> a = b + c*t + d*t**2

Then, we’re gonna instruct Python to do the double integral…

>>> x_i + integrate(v_i + integrate(a, t), t)

Finally, we have……………………………….

b*t**2/2 + c*t**3/6 + d*t**4/12 + t*v_i + x_i

We have derived a mathematically pure formula for describing \(x(t)\) from \(a(t)\)

Conclusion

Python is great for solving numeric problems ^_^

Footnotes

  1. Link To Paper: /assets/papers/100518.pdf
  2. SymPy Website: http://www.sympy.org/en/index.html
  3. Assuming that you’re a STEM undergrad student ;-)
  4. A lot of this tutorial is based on The No Bullshit Guide to Math and Physics by Ivan Savov; check out the original paper for the entire bibliography