Ask Your Question
1

help on using chain rule in Sage

asked 2017-02-20 08:25:01 +0200

lefthandstander gravatar image

Does anyone have any tips for using Sage to take derivatives of functions of many variables?

For example, if I define

w(x,y) = x^2 + y^2 (say)

and then if I suppose that x and y depend on an independent variable t, the chain rule applies for finding w.diff(t). The only way I found to do this in Sage is

var('t')

x(t) = cos(t) (say)

y(t) = sin(t)

w(x,y) = x^2 + y^2

w.diff(t)

But this isn't really using the chain rule. If I instead try

var('x,y')

(define w again)

(define x and y again)

w.diff(t)

Out: (x,y) |--> 0

Apparently it thinks the derivative is zero because it still thinks x and y are two independent variables where they appear in w, even though you get

x

Out: t |--> cos(t)

and similarly for y. Any suggestions? Thanks.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2017-02-20 11:04:15 +0200

eric_g gravatar image

What about

sage: var('t u v')
(t, u, v)
sage: x = function('x')(t)
sage: y = function('y')(t)
sage: w(u,v) = u^2 + v^2
sage: diff(w(x,y), t)
2*x(t)*diff(x(t), t) + 2*y(t)*diff(y(t), t)
edit flag offensive delete link more

Comments

Great! I see that diff(w,t) at the end gives the same behavior I was observing above. Thanks!

lefthandstander gravatar imagelefthandstander ( 2017-02-20 19:58:54 +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: 2017-02-20 08:25:01 +0200

Seen: 942 times

Last updated: Feb 20 '17