Ask Your Question
0

Sage returning wrong derivative

asked 2020-04-12 19:25:28 +0200

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: 
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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-04-12 20:22:12 +0200

Juanjo gravatar image

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.

edit flag offensive delete link more

Comments

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

Juanjo gravatar imageJuanjo ( 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.

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

Got it thanks :)

gg gravatar imagegg ( 2020-04-13 15:20:14 +0200 )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

Stats

Asked: 2020-04-12 19:25:28 +0200

Seen: 437 times

Last updated: Apr 12 '20