Ask Your Question
1

Differential system of equations in Sage

asked 2010-12-01 09:32:13 +0200

rt41323 gravatar image

updated 2010-12-01 09:34:34 +0200

Greetings all!

This is a "how do I do it in Sage" question. Let's say I have the following system of differential equations:

(a, b, p, r, and h are ALL functions of t)

eqn1 = diff(a,t) == 3*p

eqn2 = diff(b,t) == 4 + r

eqn3 = h == a^2 + b^2

NOW, I want to differentiate h from equation three (using implicit differentiation).

The "answer" would be: diff(h,t) = 2 * a * diff(a,t) + 2 * b * diff(b,t) (note that we DO know what diff(a,t) and diff(b,t) are from eqn1 and eqn2)

--> How can I get sage to differentiate eqn3, AND plug in the equations from eqn1 and eqn2 for the time derivatives of a and b?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2010-12-01 10:41:31 +0200

kcrisman gravatar image

This is a partial answer, but maybe it will help people do the second thing you want. I don't know if the obvious tuple thing will let you make all of these functions of t at once.

sage: var('t')
t
sage: h=function('h',t)
sage: a=function('a',t)
sage: b=function('b',t)
sage: p=function('p',t)
sage: r=function('r',t)
sage: diff(a^2+b^2,t)
2*a(t)*D[0](a)(t) + 2*b(t)*D[0](b)(t)
sage: z = diff(a^2+b^2,t)
sage: z.operands()[0].operands()[1]
D[0](a)(t)
sage: z.operands()[0].operands()[1].operator()
D[0](a)
sage: y = z.operands()[0].operands()[1]
sage: y
D[0](a)(t)
sage: z.substitute_expression({y:3*p})
6*a(t)*p(t) + 2*b(t)*D[0](b)(t)

but I can't think of a way to substitute with 3*p for y directly:

sage: z.substitute_expression({D[0](a)(t):3*p})
---------------------------------------------------------------------------
NameError: name 'D' is not defined

Maybe this should be implemented somehow? I hate these sorts of pattern-matching things.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2010-12-01 09:32:13 +0200

Seen: 648 times

Last updated: Dec 01 '10