# Sage returning wrong derivative

I am trying to calculate the derivative of y = e^(x*y)

Hand calculation give me the result of dy/dx = ( y*e^(x*y) ) / ( 1 - x*e^(x*y) )

But the sage is giving me the wrong output of -y/x. Here is my code:

sage:
sage:  y=function('y')(x)
sage: y
y(x)
sage:
sage: expr = exp(1)**(x*y)
sage:
sage: diff(y)
diff(y(x), x)
sage:
sage: diff(expr)
(x*diff(y(x), x) + y(x))*e^(x*y(x))
sage:
sage: solve(diff(expr), diff(y))
[diff(y(x), x) == -y(x)/x]
sage:
sage:

edit retag close merge delete

Sort by » oldest newest most voted

You don't consider the right equation to solve:

y=function('y')(x)
dy = diff(y)
derivative = solve(diff(y==exp(x*y)), dy)
derivative[0].subs(exp(x*y)==y)


This yields

diff(y(x), x) == -y(x)^2/(x*y(x) - 1)


that is, $$y'=\frac{y^2}{1-xy},$$ in agreement with your hand calculation.

more

exp(1)**(x*y) and exp(x*y) both yields e^(x*y(x)). So, I think my equation is correct. Also, why I need to call the subs method. I used the same procedure to find the derivative of many equations.

( 2020-04-13 07:05:48 +0200 )edit

Concerning the subs method, it is just a matter of taste. Don't use it if you don't like it, but I find simpler the expression I gave for $y'$. And yes, exp(1)**(x*y) and exp(x*y) both yields e^(x*y(x)). That is not the point. See the next comment.

( 2020-04-13 11:48:02 +0200 )edit

Let us get $y'$ by hand. We start with the relation $y=e^{xy}$, right? Considering $y$ as a function of $x$, we derive in both sides of this equation to get $$y'=e^{xy}(y+xy')=y(y+xy')=y^2+xyy'.$$ Hence $$y'=\frac{y^2}{1-xy},$$ as stated above. However, your Sage commands lead to get the expression of $y'$ from $$e^{xy}(y+xy')=0,$$ which is wrong.

( 2020-04-13 11:49:53 +0200 )edit

Got it thanks :)

( 2020-04-13 15:20:14 +0200 )edit