Ask Your Question
2

finding the derivative of a functional w.r.t a function

asked 2016-03-24 01:50:20 -0500

sophia gravatar image

I've defined a system as:

var('a, t'); function('x, y');

de1 = diff(x(t),t) == y(t); de2 = diff(y(t),t) == -ax(t) - (a-4)/ay(t) - y(t)^3;

I'd like to compute the derivatives of the rhs of de1 and de2 w.r.t to x(t) and y(t) (to eventually form a Jacobian matrix), i.e. the derivative of the rhs of de1 w.r.t to x(t) is Zero and w.r.t y(t) is 1. I've tried the following:

diff(de1.rhs(),y); diff(de1.rhs(),y(t)); derivative(de1.rhs(),y(t));

I get errors on all three. I'd appreciate any help. thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-29 02:42:02 -0500

nbruin gravatar image

setting F=de2.rhs(), can you use that dF/dy = dF/dt / (dy/dt) ? Would the following do the trick?

sage: F=de2.rhs()
sage: (diff(F,t) / diff(y(t),t)).subs(de1).subs(de2)
-(3*(y(t)^3 + a*x(t) + (a - 4)*y(t)/a)*y(t)^2 - a*y(t) + (y(t)^3 + a*x(t) + (a - 4)*y(t)/a)*(a - 4)/a)/(y(t)^3 + a*x(t) + (a - 4)*y(t)/a)

For the other derivatives a similar approach should apply.

edit flag offensive delete link more

Comments

Thanks a lot for replying. I tried what you suggested with de1 first, and it works when the rhs is only a function of y(t). so to compute dF/dx, i calculated it as (dF/dt)/(dx/dt) as follows:

sage: de1 = diff(x(t),t) == y(t) sage: F = de1.rhs() sage: (diff(F,t)/diff(x(t),t)).subs(de1)

the result is : D0(t)/y(t), whereas it should just be Zero.

any further suggestions would be greatly appreciated. Thank you.

sophia gravatar imagesophia ( 2016-03-29 12:19:51 -0500 )edit

Why do you think that dx/dy should be 0?

If I take x(t)=sin(t), then y(t)=cos(t) satisfies dx/dt=y . Using the chain rule, it's straightforward to check that

dy/dx=d(cos(t))/d(sin(t))

is not equal to 0.

nbruin gravatar imagenbruin ( 2016-03-29 14:38:06 -0500 )edit

your example is correct. I'm trying to accomplish something like this:

the rhs of de1 is just y(t). lets call the rhs of de1 F, so F = y(t). now dF/dy = 1. but dF/dx = 0, and that's what i'm trying to calculate - the derivative of the rhs of de1 w.r.t y and w.r.t x.

sophia gravatar imagesophia ( 2016-03-29 15:12:33 -0500 )edit

OK, in that case you should probably replace x(t), y(t) with variables and work with that:

sage: var('X,Y')
(X, Y)
sage: [[d.rhs().subs([x(t)==X,y(t)==Y]).diff(v) for d in [de1,de2]] for v in [X,Y]]
[[0, -a], [1, -3*Y^2 - (a - 4)/a]]
nbruin gravatar imagenbruin ( 2016-03-29 15:21:46 -0500 )edit

that works great, thank you!

sophia gravatar imagesophia ( 2016-03-29 21:38:43 -0500 )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: 2016-03-24 01:50:20 -0500

Seen: 142 times

Last updated: Mar 29 '16