/symdim

A python package that uses the Sympy and Astropy.units to do equation manipulation with dimensional analysis

Primary LanguagePythonMIT LicenseMIT

SymDim - SYMbolic DIMensional analysis

A python class that uses the computer algebra of SymPy and the unit system of Astropy to do equation manipulation and dimensional analysis in Jupyter Notebooks. SymPy's dimensional analysis is lacking and Astropy doesn't contain equation manipulation, so this is an attempt to combine the best of both worlds. The idea is to manipulate equations and then check the units and evaluate them as needed.

Installation

Install SymDim and its dependencies SymPy, Astropy, and num2tex with

pip install symdim

Examples:

from symdim import SymDim as S
from astropy import units as u
x = S('x', unit=u.m, value=5.0)
L = S('L', unit=u.m, value=3.0)
Zw = S('Z_w')
T0 = S('T_0', unit=u.K,value=300.0)
T0.equals(Zw**(x/L-S(1)/S(2))) # enclose '1' and '2' in SymDim so python doesn't evaluate 1/2 as 0.5
display(T0)
# now solve for Zw, whatever that is
Zw = T0.solve_for(Zw)
display(Zw)

will display

Sample Sympint output

TO-DO:

  • Add tests
  • Refactor some of the kludges
  • Add Equation class (inherit from SymPy's equations)