Ask Your Question

Sage returning wrong derivative

asked 2020-04-12 12:25:28 -0600

gg gravatar image

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:  y=function('y')(x)    
sage: y
sage: expr = exp(1)**(x*y)
sage: diff(y)
diff(y(x), x)
sage: diff(expr)
(x*diff(y(x), x) + y(x))*e^(x*y(x))
sage: solve(diff(expr), diff(y))
[diff(y(x), x) == -y(x)/x]
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2020-04-12 13:22:12 -0600

Juanjo gravatar image

You don't consider the right equation to solve:

dy = diff(y)
derivative = solve(diff(y==exp(x*y)), dy)

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.

edit flag offensive delete link 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.

gg gravatar imagegg ( 2020-04-13 00:05:48 -0600 )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.

Juanjo gravatar imageJuanjo ( 2020-04-13 04:48:02 -0600 )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.

Juanjo gravatar imageJuanjo ( 2020-04-13 04:49:53 -0600 )edit

Got it thanks :)

gg gravatar imagegg ( 2020-04-13 08:20:14 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-04-12 12:25:28 -0600

Seen: 67 times

Last updated: Apr 12 '20