Printing Math with Sympy in Python

Shen Ge
CodeX
Published in
2 min readNov 19, 2021

--

Photo by Scott Graham on Unsplash

The Python library sympy is wonderful in doing symbolic calculations but unfortunately the results can be hard to read. For instance, I wanted to find the integral of u=(k3+k4*t)*cos(k1+k2*t) with respect to time (which I call the variable t) with the k1, k2, k3 and k4 as constants. This is what was in my script:

from sympy import *
k1,k2,k3,k4 = symbols('k1 k2 k3 k4')
t = Symbol('t',positive=True)
u =…

--

--

Shen Ge
CodeX
Writer for

Engineer and console operator who helped America land back on the moon 2/22/2024. Enjoys code + poetry. Become a member: https://medium.com/@shenge86/membership