Partial differentiation on Sage

68 views
Skip to first unread message

saad khalid

unread,
Feb 29, 2016, 6:13:10 PM2/29/16
to sage-support
Hey everyone. So, here's the problem I have:

z = x^2 + y^2
x = r*cos(theta)
y = r*sin(theta)

I need to calculate the partial derivative (dz/dx) while holding r constant. I was hoping I could define all of those functions and then just use the derivative command, but it doesn't seem to work the way I'm looking for. I also don't know how to tell sage to keep a variable constant. Note that, in this problem, the partial derivative is equal to -2x (if this were a very basic partial derivative, not involving having to keep anything constant, it would have been 2x).

Here is the code I tried:

r,theta,y = var("r,theta,y")
x
= r*cos(theta)
f1
= x^2 + y^2
f1
(x).diff(x)

I'm getting 2x as the output, when what I want is -2x. What am I doing wrong?

Thanks!



Anton Sherwood

unread,
Mar 1, 2016, 12:44:17 AM3/1/16
to sage-s...@googlegroups.com
On 2016-2-29 15:13, saad khalid wrote:
> Hey everyone. So, here's the problem I have:
>
> z = x^2 + y^2
> x = r*cos(theta)
> y = r*sin(theta)
>
> I need to calculate the partial derivative (dz/dx) while holding r
> constant. [...]

Seems to me what you want is z_theta / x_theta, i.e., the ratio of two
partial derivatives with respect to theta, which of course assumes
constant r.

--
*\\* Anton Sherwood *\\* www.bendwavy.org

Anton Sherwood

unread,
Mar 1, 2016, 3:48:03 AM3/1/16
to sage-s...@googlegroups.com
On 2016-2-29 15:13, saad khalid wrote:
> r,theta,y =var("r,theta,y")
> x =r*cos(theta)
> f1 =x^2+y^2
> f1(x).diff(x)
> |
>
> I'm getting 2x as the output, when what I want is -2x. What am I doing
> wrong?

When you take the partial derivative of f1 with respect to x,
you hold y constant and ignore r.
Reply all
Reply to author
Forward
0 new messages