<p>Unit conversion and handling is good in Astropy, if you need to convert astronomical units I recommend that you do use that package.</p>
<p>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).</p>

CC BY-SA 4.0
2020-12-30T15:15:48.707Z
I came to the same conclusion. Looks like Mathematica is the way to go if the problem is about numerical solving with units
Nickpick
CC BY-SA 4.0
2020-12-30T15:14:04.407Z
2020-12-30T15:14:04.407Z
sbjartmar
<p>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:</p>
<p>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?</p>
<p>Essentially what I need is</p>
<ul>
<li>Equation solver (Mathematica or Astropy combined with Sympy?)</li>
<li>Unit conversion (Mathematica and Astropy)</li>
</ul>
<p>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.</p>
<p>As an example problem:
How would I solve for a variable in kepler's third law after assigning values to all other variables?</p>
<p><code>a^3/P^2 = G * (Ms + Mp) / 4 * pi^2</code></p>
<p>It seems simple in Mathematica doing <code>Solve[a^3/P^2 == (G (Ms + Mp))/(4 \[Pi]^2), P]]</code>. Is there any equivalent in python that can solve and at the same time handle units?</p>

CC BY-SA 4.0
2020-12-28T17:22:16.147Z
*...in a scalable way...*  In what way "scalable" ?
StephenG - Help Ukraine
CC BY-SA 4.0
2020-12-28T20:10:38.107Z
I like Matlab but most people here just use Python.
Connor Garcia
CC BY-SA 4.0
2020-12-29T17:41:43.237Z
But how would you solve a simple problem like: `a^3/P^2 = G * (Ms + Mp) / 4 * pi^2`, adding values to variables and solving for the remaining variable? [edited the question]
Nickpick
CC BY-SA 4.0
2020-12-29T20:26:36.277Z
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.
James K
CC BY-SA 4.0
2020-12-29T22:21:17.687Z
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.
Nickpick
CC BY-SA 4.0
2020-12-29T22:54:08.707Z
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.
James K
CC BY-SA 4.0
2020-12-29T22:56:03.057Z
Generally I have no problem doing the math by hand, but at the same time I believe it’s fine to use the computer as a bicycle for the mind and drive faster.
Nickpick
CC BY-SA 4.0
2020-12-30T15:35:55.037Z
BTW, you should avoid G when possible and instead use the [standard gravitational parameter](https://en.wikipedia.org/wiki/Standard_gravitational_parameter).
PM 2Ring
CC BY-SA 4.0
2021-01-02T01:30:16.737Z
I think the question can have fact-based answers, voting to **leave open** so that those answers can be posted; closing blocks answer-posting!
uhoh
<software><units>
Mathamatica vs Sympy and Astropy to solve basic astronomy problems: solving linear equations and unit conversion
Nickpick
# Mathamatica vs Sympy and Astropy to solve basic astronomy problems: solving linear equations and unit conversion

(Asked by: username_0 on 2020-12-28)

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?

**Tags:** software, units

> **Comments:**
> **username_1**: *...in a scalable way...*  In what way "scalable" ?  
> **username_2**: I like Matlab but most people here just use Python.  
> **username_0**: But how would you solve a simple problem like: `a^3/P^2 = G * (Ms + Mp) / 4 * pi^2`, adding values to variables and solving for the remaining variable? [edited the question]  
> **username_3**: 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.  
> **username_0**: 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.  
> **username_3**: 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.  
> **username_0**: Generally I have no problem doing the math by hand, but at the same time I believe it’s fine to use the computer as a bicycle for the mind and drive faster.  
> **username_4**: BTW, you should avoid G when possible and instead use the [standard gravitational parameter](https://en.wikipedia.org/wiki/Standard_gravitational_parameter).  
> **username_5**: I think the question can have fact-based answers, voting to **leave open** so that those answers can be posted; closing blocks answer-posting!  

---

## 1 answers

### Answer by username_6 on 2020-12-30. Score: 1 | Accepted answer

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).

> **Comments:**
> **username_0**: I came to the same conclusion. Looks like Mathematica is the way to go if the problem is about numerical solving with units  

---

