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

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 close merge delete

Sort by » oldest newest most voted

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.

more

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.

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.

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.

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]]