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

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
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]

Categories

HOME
notepad++
phantom-dsl
telegram
android-studio-2.2
powerpoint
jelastic
seo
rom
dojo
nested-if
limit
vsm
missing-data
boto3
computer-science
pattern-matching
mxgraph
nancy
dynatrace
magnetic-cards
dynamic-sql
feathersjs
foreign-keys
cfml
google-maps-autocomplete
googlebot
imagemap
jquery-callback
fable-f#
quantlib
testcomplete
dst
gojs
sendbird
sql-delete
xajax
engine.io
reason
zoomify
release
ods
verifiable-c
p4merge
spring-mvc-test
visa
levenshtein-distance
android-ibeacon
congestion-control
apache-directory
strftime
optimizely
servermanager
jboss-4.2.x
openrasta
netbeans6.8
mongotemplate
lightning
aquamacs
subnet
opengl-4
type-theory
java-websocket
trigger.io
gameplay-kit
shinobi
cvxpy
materialized-path-pattern
node-request
usart
simplepie
builtins
spring-cloud-feign
windows-azure-queues
qiime
httpruntime.cache
spring-retry
character-replacement
viola-jones
liquid-layout
skspritenode
matlab-deployment
uncaught-typeerror
easyrtc
human-computer-interface
live555
xml-dsig
file-not-found
koala
eclipse-kepler
scrypt
script#
mvc-editor-templates
curb
jquery-blockui
uimanageddocument
stress
apache-commons-dbutils
urlrewriter
node-redis
creole
cgbitmapcontextcreate
django-paypal
facebook-iframe
object-database
interprocess
mathematical-notation
asynchronous-wcf-call
information-management
idatareader

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