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]

Categories

HOME
fabricjs
azure-stream-analytics
polymer
c++11
apache-flink
google-spreadsheet
swt
saml-2.0
socket.io
pclxl
javacc
newrelic
missing-data
jax-ws
azure-container-service
title
fabric.io
android-securityexception
opengl-es-3.0
angular-dart
google-form
stellar.js
gource
enterprise-architect
flash-player
gruntfile
esoteric-languages
xmonad
google-container-registry
rubymotion
spring-async
jquery-ias
href
ember-cli
imageresizer
php-mysqlidb
easeljs
tosca
monit
jquery-callback
beautifier
linked-data
firebase-analytics
tpm
bringtofront
google-earth
mustache
angularjs-material
memory-address
autolisp
rselenium
dsx-desktop
getpixel
arduino-ide
yowsup
ods
typesafe-config
spring-mvc-test
vmware-fusion
microsoft-metro
dapper-simplecrud
convex-optimization
google-cse
carrot2
static-cast
trigger.io
swingworker
pocketsphinx-android
cronexpression
grails-plugin
autosar
builtins
beamer
inf
doctype
eoferror
baasbox
liquid-layout
botan
canvg
aspectj-maven-plugin
dot.js
java-security
procedural-programming
viewer
big-ip
metatrader5
genymotion-call
raygun
ss7
clickbank
multiautocompletetextview
sbcl
spring-3
http-patch
embedded-fonts
code-duplication
beaker-testing
superscrollorama
dajaxice
objectquery
ilasm
floating-point-exceptions
infobright
entity-attribute-value
screen-size
tournament
event-receiver
socketserver
photolibrary
isapi-extension
zend-rest
purepdf
web-application-project
business-model

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App