Look how the partial derivatives of atan2 are defined:
(defgrad %atan2 ($x $y)
#$$y/(y^2+x^2)$
#$$-(x/(y^2+x^2))$)
Now when we differentiate an atan2 expression that uses exactly these arguments x and y, but in reverse order, we get bogus answers:
/* Wrong with arguments named y and x: */
(%i1) diff(atan2(y,x),x);
(%o1) -(1/(2*x))
(%i2) diff(atan2(y,x),y);
(%o2) 1/(2*x)
/* Correct when renaming arguments: */
(%i3) diff(atan2(yy,xx),xx);
(%o3) -(yy/(yy^2+xx^2))
(%i4) diff(atan2(yy,xx),yy);
(%o4) xx/(yy^2+xx^2)
Oops. The derivatives should use
$xand$y.defgradshould probably do more error checking. Maybe make sure every variable in the derivatives start with a$?I think the problem is that variables are substituted sequentially using
substitutelinstead of in parallel using$psubstitute. I'm on it.Fixed by commit [7bda3f] by using
$psubstitute.Related
Commit: [7bda3f]