### trigonometry

#### Sympy cancelling terms in the Jacobian of polar coordinates transformation

I am preparing examples of how a Jacobian is arrived at using transformations from polar/cartesian parametrisations. My question is twofold. First, I want to know how to force sympy to cancel out terms following substitution. The two matrices are: J1 = Matrix([[(r*cos(theta)).diff(r), (r*cos(theta)).diff(theta)],[(r*sin(theta)).diff(r),(r*sin(theta)).diff(theta)]]) J2 = Matrix([[((x**2+y**2)**(1/2.)).diff(x),((x**2+y**2)**(1/2.)).diff(y)],[atan(y/x).diff(x),atan(y/x).diff(y)]]) #substitute for x,y to have same variables for J1 and J2 J2 = trigsimp(J2.subs({x:r*cos(theta), y:r*sin(theta)})) J2 I expected that using cancel(), or even evalf() would have removed the r/(r^2)^1/2= 1 term, but it did not. Second, how or can one require sympy to recognise simple identities, in this case sin^2+cos^2 = 1? This is so that the result is an evaluated identity matrix from J1*J2. This works, as per documentation: simplify(r/(r**2)**(1/2)*(sin(theta)**2+cos(theta)**2)) This equivalent(ish) equation does not. J = J1*J2 simplify(J[0,0]) It seems that the second error is a consequence of the first.

Mathematically, r/(r^2)^1/2= 1 is not always true. It's true if r is a nonnegative number, which it is in polar coordinates. So you should tell SymPy this: r = Symbol('r', nonnegative=True) theta, x, y = symbols('theta x y') (Mathematically, you can even assume r strictly positive, positive=True, since at the origin derivatives in polar coordinates don't work anyway.) The output will be much more agreeable: [[1.0*cos(theta), 1.0*sin(theta)], [-sin(theta)/r, cos(theta)/r]] Only this 1.0 is annoying, where does it come from? It comes from 1/2. being a float instead of a rational number. Use Rational(1, 2) to have a rational number in the exponent (important for simplification). In this case, the exponent being 1/2, it's more natural to use sqrt which has the same effect of making the exponent rational and is easier to type. sqrt(x**2+y**2).diff(x) The end result is [[cos(theta), sin(theta)], [-sin(theta)/r, cos(theta)/r]] As for trigonometric simplification, trigsimp(J1*J2) does return the identity matrix.

### Related Links

Calculating collisions with Radians incrementing

How do arbitrary-precision libraries like mpmath evaluate simple trigonometric functions?

How can I calculate the angle

Finding Shortest Distance Between Two Parallel Lines, With Arbitrary Point [closed]

how to convert depth in Z-cordinate

How can I simplify this expression with trigonometric in Maple?

Require trigonometry assistance with ship/wave movement

Trigonometry - Find where two curves intersect

How to calculate point 'along' unit circle radian [closed]

Issues with bullet entry points for “shoulder mounted” guns

Using the coordinates of two of a triangle's vertices to calculate the coordinates of the third

How to do the trig function Arc Cos (ACOS() in Excel) in MS-Access?

How to get the direction (angle) of rectangle after rotating it from a pivot point

How to calculate points of Chord

Is trigonometry computationally expensive?

draw lines protruding from a circle [closed]