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

How to calculate Heading using Gyro and magnetometer
Integral of a sign function proof
Best way working with trigonometric functions
Calculate place of point C to be equal distance away from points A and B
How to compute sum of angles from sine and cossine?
Counting trig ops as measure() function to fu() in sympy
Find a coordinate along a path
Angle calculation resulting in strange behavior
Shift angle orientation using atan2
estimate angle between two lines y = 1000x and y = 999x
Need help revising a simple formula to make it universal
SWIFT trig functions
Simplifying atan(tan(a+b))
2 Different Radians constant calcuations whats the difference?
Trigonometry & Sunset
Calculating collisions with Radians incrementing

Categories

HOME
batch-file
fabricjs
scikit-learn
prism
cheerio
time-complexity
spring-data-redis
angularfire2
opengl-3
extjs4.2
accessibility
fosrestbundle
google-chrome-app
dkim
distribution
why3
redis-sentinel
datastage
angular-dart
supervisor
radgridview
internationalization
red5
xmonad
sencha-touch
guzzle
systemtime
angular-routing
dynamically-generated
froala
onload
moses
interbase
delimiter
amazon-quicksight
inversion-of-control
spotipy
bringtofront
ceylon
google-earth
nsurl
memory-address
android-gridview
github3.py
activexobject
slacktextviewcontroller
searchkit
parse-tree
amazon-ses
odroid
mcustomscrollbar
magento-1.9.3
knime
apache-spark-dataset
facebook-social-plugins
optimizely
plan-9
fwrite
arq
pair-programming
opengl-4
janus
d3-force-directed
cmp
flex-monkey
uicolor
i386
jtwig
kiosk
libvlc
opserver
coda
.bash-profile
atoi
keyup
alloy-ui
zend-currency
cryptographichashfunction
ejb-2.x
theos
beatsmusic
ssis-data-flow
crowd
deform
universal-image-loader
reflector
grails-plugin-rabbitmq
maven-scm
mt4j
merb
octal
pagedown
traceability
adobe-media-server
correlated-subquery
cuda-gdb
apache-whirr
koken
relative
u2netdk
google-floodlight
cgbitmapcontextcreate
timthumb
office-2007
web-garden
echo3
web-application-project
interop-domino
fault-tolerance
product-management
pbcopy

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