I realize this may be slightly off topic, but I also believe this is probably the best way to get an answer to my question:

What is the best combination of software packages / programming languages to solve basic astronomy questions, such as applying Kepler's laws, calculating radial velocities (i.e. basic linear algebra) etc in a scalable way?

Essentially what I need is

  • Equation solver (Mathematica or Astropy combined with Sympy?)
  • Unit conversion (Mathematica and Astropy)

I'd like to hear some opinions what combination of tools people are using to perform basic astronomy calculations such as the above example, where unit-conversion and solving linear equations appear to be the most common tasks.

As an example problem: How would I solve for a variable in kepler's third law after assigning values to all other variables?

a^3/P^2 = G * (Ms + Mp) / 4 * pi^2

It seems simple in Mathematica doing Solve[a^3/P^2 == (G (Ms + Mp))/(4 \[Pi]^2), P]]. Is there any equivalent in python that can solve and at the same time handle units?

  • 3
    $\begingroup$ ...in a scalable way... In what way "scalable" ? $\endgroup$ Dec 28, 2020 at 17:22
  • 2
    $\begingroup$ I like Matlab but most people here just use Python. $\endgroup$
    – Connor Garcia
    Dec 28, 2020 at 20:10
  • 2
    $\begingroup$ The issue of "scalability" is key here. What you don't want to do is get the computer to do symbolic algebra each time. You rearrange the formula once P=sqrt(4*a^3*pi^2/(G*(Ms+Mp)) and then get the computer to evaluate it. Python is a good choice to do the evaluations. I also don't get "handle units" that is part of the programmer's task. This is non-linear, but solving linear equations is the same: You do the the symbolic re-arrangement once (or get mathematica/wolfram alpha to do it), you then get the computer to do the evaluation for different values. $\endgroup$
    – James K
    Dec 29, 2020 at 20:26
  • 1
    $\begingroup$ Yes that’s certainly a possibility way. But in my case I’m working through an astronomy book and I have many difference problems to solve, need to mix formulas together and convert units etc. Mathematica works great, but I would prefer a similarly flexible solution in python. So far I couldn’t find one. $\endgroup$
    – Nickpick
    Dec 29, 2020 at 22:21
  • 4
    $\begingroup$ Can I humbly suggest that you do the algebra by hand. Your maths, and hence your astronomy will be much better if you sweat a little to get the answers. $\endgroup$
    – James K
    Dec 29, 2020 at 22:54

1 Answer 1


Unit conversion and handling is good in Astropy, if you need to convert astronomical units I recommend that you do use that package.

Regarding symbolic equations, SymPy is good, but you'd probably be better off doing theoretical work to figure out the units of the outcome and just plugging float numbers into Python. From my experience, having Python solve with units involved is time consuming (especially if you want a scalable solution).

  • $\begingroup$ I came to the same conclusion. Looks like Mathematica is the way to go if the problem is about numerical solving with units $\endgroup$
    – Nickpick
    Dec 30, 2020 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .