Calculus in Spherical Coordinates With Python
Your Daily Dose of Scientific Python
Published in
4 min readNov 9, 2022
About this series: Applying the Python scientific stack to real-world problems requires a lot of practice. To help you on your journey to mastery, follow this series and solve common (and not-so-common) problems using NumPy, SymPy, SciPy, and matplotlib.
Today’s Problem
Use sympy to calculate the following quantities in spherical coordinates:
- the unit base vectors
- the line element 𝑑𝑠
- the volume element 𝑑𝑉=𝑑𝑥𝑑𝑦𝑑𝑧
- and the gradient.
Solution With SymPy
First, we define the symbols for the coordinates. To get cleaner results we explicitly state which quantities are real and positive: