[Edited to answer your second question as well.]
To replace diff(psi)
by say t
, use substitute_expression
as follows:
sage: t = var('t')
sage: psi = function('psi',t)
sage: a = 3 * diff(psi)^2 - 2 * diff(psi) + 1
sage: a
3*D[0](psi)(t)^2 - 2*D[0](psi)(t) + 1
sage: a.substitute_expression(diff(psi)==t)
3*t^2 - 2*t + 1
To use the result of solve
to perform replacement, do as follows:
sage: var('V V_f chi l psi')
sage: eq0 = V == V_f * cos(chi)
sage: eq1 = l * psi == V_f * sin(chi)
sage: sol = solve(eq0, V_f)
sage: sol
[V_f == V/cos(chi)]
sage: eq0.subs_expr(sol[0])
V == V
sage: eq1.subs_expr(sol[0])
l*psi == V*sin(chi)/cos(chi)
Note that sol
is a list containing one equation. We use that equation (item 0 of the list) for the replacement.