Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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 :

  1. r = var("r") # creates a variable denoted by r
  2. ex = somexepression(r) # uses it
  3. r1 = var("r1") # creates a new, temporary, symbol denoting a variable
  4. ex1 = ex.subs({r:r1}) # a new, temporary, expression ; $r1=r \Rightarrow ex1 = ex$.
  5. r = function("r") # the symbol r now denotes a function, whose expression is r-free
  6. ex = ex1.subs({r1:r(t)}) # the variable r1 can now be replaced by the expression r(t)in ex1
  7. `reset("ex1, r1") # Housekeeping cleanup...

HTH,