Skip to content

Instantly share code, notes, and snippets.

@andrezsanchez
Created July 31, 2022 23:32
Show Gist options
  • Save andrezsanchez/cd6c0d8a231da38d417ea854615ec685 to your computer and use it in GitHub Desktop.
Save andrezsanchez/cd6c0d8a231da38d417ea854615ec685 to your computer and use it in GitHub Desktop.
Calculating an inverse jacobian matrix
from sympy import Matrix, symbols, sin, cos, pi
r, lat, lng = symbols('r lat lng')
sphericalToCartesian = Matrix([r*sin(lat)*cos(lng), r*sin(lat)*sin(lng), r*cos(lat)])
jacobian = sphericalToCartesian.jacobian(Matrix([r, lat, lng]))
print(jacobian)
inverseJacobian = jacobian.inv()
inverseJacobian.simplify()
print(inverseJacobian)
# Now substitute values for the radius, latitude, and longitude.
# print(a.subs([(r, 1), (g, pi/2), (f, pi/2)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment