In [1]:
from sympy import (symbols, pi, Lambda,
Matrix, sqrt, atan2,
cos, sin, Derivative, Eq)
from IPython.display import HTML
In [2]:
x, y, z = symbols('x y z', real=True)
r, theta, phi = symbols('r theta phi', nonnegative=True)
In [3]:
car2d = Matrix([x, y])
pol = Matrix([r, theta])
display(car2d, pol)
In [4]:
J2d_car2d_pol = symbols('\\textrm{J}_{car2d}^{pol}')
J2d_car2d_pol
Out[4]:
In [5]:
J2d_car2d_pol_m = Matrix([[Derivative(r, x), Derivative(r, y)],
[Derivative(theta, x), Derivative(theta, y)]])
J_eq = Eq(J2d_car2d_pol, J2d_car2d_pol_m, evaluate = False)
display(
J_eq
)
In [6]:
J2d_car2d_pol_m = J2d_car2d_pol_m.subs({r: sqrt(x**2+y**2), theta: atan2(y, x)})
J2d_car2d_pol_m
Out[6]:
In [7]:
J2d_car2d_pol_m.doit()
Out[7]:
In [8]:
J2d_pol_car2d = symbols('\\textrm{J}_{pol}^{car2d}')
J2d_pol_car2d
Out[8]:
In [9]:
J2d_pol_car2d_m = Matrix([[Derivative(x, r), Derivative(x, theta)],
[Derivative(y, r), Derivative(y, theta)]])
J_eq = Eq(J2d_pol_car2d, J2d_pol_car2d_m, evaluate = False)
display(
J_eq
)
In [10]:
J2d_pol_car2d_m = J2d_pol_car2d_m.subs({x: r*cos(theta), y: r*sin(theta)})
J2d_pol_car2d_m
Out[10]:
In [11]:
J2d_pol_car2d_m.doit()
Out[11]:
In [12]:
car3d = Matrix([x, y, z])
sphe = Matrix([r, theta, phi])
display(car3d, sphe)
In [13]:
J3d_car3d_sphe = symbols('\\textrm{J}_{car3d}^{sphe}')
J3d_car3d_sphe
Out[13]:
In [14]:
J3d_car3d_sphe_m = Matrix([[Derivative(r, x), Derivative(r, y), Derivative(r, z)],
[Derivative(theta, x), Derivative(theta, y), Derivative(theta, z)],
[Derivative(phi, x), Derivative(phi, y), Derivative(phi, z)]])
J3d_car3d_sphe_m
Out[14]:
In [15]:
J3d_car3d_sphe_m = J3d_car3d_sphe_m.subs({r: sqrt(x**2 + y**2 + z**2), theta: atan2(y, x), phi: atan2(z, sqrt(x**2 + y**2))})
J3d_car3d_sphe_m
Out[15]:
In [16]:
J3d_car3d_sphe_m.doit()
Out[16]:
In [ ]:
In [17]:
J3d_sphe_car3d = symbols('\\textrm{J}_{sphe}^{car3d}')
J3d_sphe_car3d
Out[17]:
In [18]:
J3d_sphe_car3d_m = Matrix([[Derivative(x, r), Derivative(x, phi), Derivative(x, theta)],
[Derivative(y, r), Derivative(y, phi), Derivative(y, theta)],
[Derivative(z, r), Derivative(z, phi), Derivative(z, theta)]])
J3d_sphe_car3d_m
Out[18]:
In [19]:
J3d_sphe_car3d_m = J3d_sphe_car3d_m.subs({x: r*cos(phi)*cos(theta), y: r*cos(phi)*sin(theta), z:r*sin(phi)})
J3d_sphe_car3d_m
Out[19]:
In [20]:
J3d_sphe_car3d_m.doit()
Out[20]:
In [ ]: