Previously, x and y were callable symbolic expressions x(t) and y(t).
So how should i define H in 'In [2]', so that 'In [4]' shows the expected result.
Complement : Sage’s notation for derivatives is somewhat baroque, and this does not help in the present case.
Here, both k and x are functions of t ; writing h as a function of x and k is just an intricate way to write a function of t, unique independent variable.
As for notations : what we’d “manually” write in this case would be :
and we could deduce
.
Sage doesn’t have a direct notation for denoting derivative with respect to another function ; instead, it uses the Doperator, which creates derivative operators :
sage: t=var("t") sage: h, x=function("h, x") sage: diff(h(x(t)), t) D[0](h)(x(t))*diff(x(t), t) sage: diff(h(x(t)), t)/diff(x(t), t) D[0](h)(x(t))Eric’s notation is an elegant way to work around this problem.
The use of standard notations leads to :
sage: r, t, alpha, delta, r = var('r, t, alpha, delta, r') sage: k, x, lambda_ = function("k, x, lambda_") sage: h(t) = k(t)*(1-x(t))*e^(-r*t) + lambda_(t)*(k(t)^alpha*x(t)-delta*k(t)) sage: D[0](h)(x(t)) r*(x(x(t)) - 1)*e^(-r*x(t))*k(x(t)) - (x(x(t)) - 1)*e^(-r*x(t))*D[0](k)(x(t)) - e^(-r*x(t))*k(x(t))*D[0](x)(x(t)) + (alpha*k(x(t))^(alpha - 1)*x(x(t))*D[0](k)(x(t)) - delta*D[0](k)(x(t)) + k(x(t))^alpha*D[0](x)(x(t)))*lambda_(x(t)) - (delta*k(x(t)) - k(x(t))^alpha*x(x(t)))*D[0](lambda_)(x(t))Not a pretty sight…
Dear Emmanuel,The results of your approach might not be pretty. Unfortunatly I think they seem to be wrong too.See:sage: r, t, alpha, delta, r = var('r, t, alpha, delta, r')
sage: k, x, lambda_ = function("k, x, lambda_")sage: h1(t) = x(t)*e^(-r*t)sage: D[0](h1)(x(t))-r*e^(-r*x(t))*x(x(t)) + e^(-r*x(t))*D[0](x)(x(t))Kindly note the "x(x(t))" in the first term. :-/