Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

Sage returning wrong derivative

asked 5 years ago

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:
Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 5 years ago

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=y21xy, in agreement with your hand calculation.

Preview: (hide)
link

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 ( 5 years ago )

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 ( 5 years ago )

Let us get y by hand. We start with the relation y=exy, right? Considering y as a function of x, we derive in both sides of this equation to get y=exy(y+xy)=y(y+xy)=y2+xyy. Hence y=y21xy, as stated above. However, your Sage commands lead to get the expression of y from exy(y+xy)=0, which is wrong.

Juanjo gravatar imageJuanjo ( 5 years ago )

Got it thanks :)

gg gravatar imagegg ( 5 years ago )

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: 5 years ago

Seen: 827 times

Last updated: Apr 12 '20