Posts about sympy
SymPy for physics homework in 2020
I've been doing my university physics homework in SymPy and Jupyter for a little bit, and I thought I could share a little about the workflow I've developed for it. It might come useful for you.
Parsing and plotting LaTeX expressions with SymPy
Today let's look into some pretty neat SymPy functionality. I was in a fluid dynamics lecture, practicing taking notes with LaTeX on the go and stumbled upon this monstrosity:
$$ \Delta(k) = \frac{\rho_1-\rho_2}{\rho_1 + \rho_2} gk + \frac{\gamma k^3}{\rho_1 + \rho_2} - \frac{\rho_1 \rho_2}{(\rho_1 + \rho_2)^2} U^2 k^2 $$(bonus points for whoever recognizes this!)
We were supposed to draw this for a few example sets of values. All right! I opened up pinta
and scribbled a few squiggly lines with my small touchpad, following the blackboard drawings. It looked darn ugly, but that got me thinking. SymPy
has parsers, right? Can't I just parse that LaTeX equation into Python and make that plot pretty with matplotlib?
Well, as it turns out, sure...
the_plot.show()
But it takes some tinkering.