If r
and theta
are functions (of time, I assume), note them as such :
var("L r rdot theta thetadot t e d c G M r_s")
r = function("r")
theta = function("theta")
rdot(t) = diff(r(t), t)
thetadot(t) = diff(theta(t), t)
K2(t) = (1-(rdot(t)**2+r(t)**2*thetadot(t))/c**2)/(1-rdot(t)/c)**2
# This is meaningless :
# eq1=diff(K2,rdot)
eq1 = diff(K2(t), t)
eq2 = diff(eq1(t), t)
eq1
is
sage: eq1
t |--> 2*((r(t)^2*diff(theta(t), t) + diff(r(t), t)^2)/c^2 - 1)*diff(r(t), t, t)/(c*(diff(r(t), t)/c - 1)^3) - (2*r(t)*diff(r(t), t)*diff(theta(t), t) + r(t)^2*diff(theta(t), t, t) + 2*diff(r(t), t)*diff(r(t), t, t))/(c^2*(diff(r(t), t)/c - 1)^2)
$$ t \ {\mapsto}\ \frac{2 \, {\left(\frac{r\left(tright)^{2} \frac{\partial}{\partial t}theta\left(tright) + \frac{\partial}{\partial t}r\left(tright)^{2}}{c^{2}} - 1right)} \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright)}{c {\left(\frac{\frac{\partial}{\partial t}r\left(tright)}{c} - 1right)}^{3}} - \frac{2 \, r\left(tright) \frac{\partial}{\partial t}r\left(tright) \frac{\partial}{\partial t}theta\left(tright) + r\left(tright)^{2} \frac{\partial^{2}}{(\partial t)^{2}}theta\left(tright) + 2 \, \frac{\partial}{\partial t}r\left(tright) \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright)}{c^{2} {\left(\frac{\frac{\partial}{\partial t}r\left(tright)}{c} - 1right)}^{2}} $$
Similarly, eq2 is :
sage: eq2
t |--> 2*((r(t)^2*diff(theta(t), t) + diff(r(t), t)^2)/c^2 - 1)*diff(r(t), t, t, t)/(c*(diff(r(t), t)/c - 1)^3) - (2*diff(r(t), t)^2*diff(theta(t), t) + 2*r(t)*diff(r(t), t, t)*diff(theta(t), t) + 4*r(t)*diff(r(t), t)*diff(theta(t), t, t) + r(t)^2*diff(theta(t), t, t, t) + 2*diff(r(t), t, t)^2 + 2*diff(r(t), t)*diff(r(t), t, t, t))/(c^2*(diff(r(t), t)/c - 1)^2) - 6*((r(t)^2*diff(theta(t), t) + diff(r(t), t)^2)/c^2 - 1)*diff(r(t), t, t)^2/(c^2*(diff(r(t), t)/c - 1)^4) + 4*(2*r(t)*diff(r(t), t)*diff(theta(t), t) + r(t)^2*diff(theta(t), t, t) + 2*diff(r(t), t)*diff(r(t), t, t))*diff(r(t), t, t)/(c^3*(diff(r(t), t)/c - 1)^3)
$$ t \ {\mapsto}\ \frac{2\, {\left(\frac{r\left(tright)^{2} \frac{\partial}{\partial t}theta\left(tright) + \frac{\partial}{\partial t}r\left(tright)^{2}}{c^{2}} - 1right)} \frac{\partial^{3}}{(\partial t)^{3}}r\left(tright)}{c {\left(\frac{\frac{\partial}{\partial t}r\left(tright)}{c} - 1right)}^{3}} - \frac{2 \, \frac{\partial}{\partial t}r\left(tright)^{2} \frac{\partial}{\partial t}theta\left(tright) + 2 \, r\left(tright) \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright) \frac{\partial}{\partial t}theta\left(tright) + 4 \, r\left(tright) \frac{\partial}{\partial t}r\left(tright) \frac{\partial^{2}}{(\partial t)^{2}}theta\left(tright) + r\left(tright)^{2} \frac{\partial^{3}}{(\partial t)^{3}}theta\left(tright) + 2 \, \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright)^{2} + 2 \, \frac{\partial}{\partial t}r\left(tright) \frac{\partial^{3}}{(\partial t)^{3}}r\left(tright)}{c^{2} {\left(\frac{\frac{\partial}{\partial t}r\left(tright)}{c} - 1right)}^{2}} - \frac{6 \, {\left(\frac{r\left(tright)^{2} \frac{\partial}{\partial t}theta\left(tright) + \frac{\partial}{\partial t}r\left(tright)^{2}}{c^{2}} - 1right)} \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright)^{2}}{c^{2} {\left(\frac{\frac{\partial}{\partial t}r\left(tright)}{c} - 1right)}^{4}} + \frac{4 \, {\left(2 \, r\left(tright) \frac{\partial}{\partial t}r\left(tright) \frac{\partial}{\partial t}theta\left(tright) + r\left(tright)^{2} \frac{\partial^{2}}{(\partial t)^{2}}theta\left(tright) + 2 \, \frac{\partial}{\partial t}r\left(tright) \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright)right)} \frac{\partial^{2}}{(\partial t)^{2}}r\left(tright)}{c^{3} {\left(\frac{\frac{\partial}{\partial t}r\left(tright)}{c} - 1right)}^{3}} $$
As already noted, if r
is a function (presumably of time) and rdot
its derivative w. r. t. time, diff(K2,rdot)
is meaningless...
Note : eric_g
answer is correct, but cannot be used in your case, since you want to replace a symbol by a function with the same name. You need to take a few steps :
r = var("r")
# creates a variable denoted by r
ex = somexepression(r)
# uses it r1 = var("r1")
# creates a new, temporary, symbol denoting a variable ex1 = ex.subs({r:r1})
# a new, temporary, expression ; $r1=r \Rightarrow ex1 = ex$. r = function("r")
# the symbol r now denotes a function, whose expression is r
-free ex = ex1.subs({r1:r(t)})
# the variable r1
can now be replaced by the expression r(t)
in ex1
- `reset("ex1, r1") # Housekeeping cleanup...
HTH,
What
eq1=diff(K2,rdot)
means when you substituterdot(t)
tordot
? The rerivative of K2 mus be taken with respect to,what ?