0

I'm trying to perform implicit differentiation to the function Lrdot which is -2*rdot/(1 - 1/r(t)), wrt an affine parameter s, where rdot is dr/ds. The error below pops up and i'm not sure how to debug.

from sympy import *
from sympy.physics.mechanics import *

r   = dynamicsymbols('r')
rdot  = dynamicsymbols('r', 1)

t   = dynamicsymbols('t')
tdot = dynamicsymbols('t', 1)

phi   = dynamicsymbols('phi')
phidot = dynamicsymbols('phi', 1)

s = symbols('s')

def F(x):
    return 1-(1/x)

# Largangian
def L(a,b,c, adot, bdot, cdot, photon = true): #r,t,phi
    return F(a)*(bdot)**2 - adot**2/F(a) - (a*cdot)**2

L = L(r, t, phi, rdot, tdot, phidot, photon = true)


Lr = diff(L, r)
Lrdot = diff(L, rdot)


diffLrdot =  idiff(-2*rdot/(1-1/r), r, s)
print(diffLrdot)
Traceback (most recent call last):
  File "/Users/myname/PycharmProjects/untitled/.idea/14.1.py", line 40, in <module>
    diffLrdot =  idiff(-2*rdot/(1-1/r), r, s)
  File "/Users/myname/PycharmProjects/untitled/venv/lib/python3.6/site-packages/sympy/geometry/util.py", line 578, in idiff
    f = {s: Function(s.name)(x) for s in eq.free_symbols
  File "/Users/myname/PycharmProjects/untitled/venv/lib/python3.6/site-packages/sympy/geometry/util.py", line 579, in <dictcomp>
    if s != x and s in dep}
NameError: free variable 'dep' referenced before assignment in enclosing scope
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
  • it should be `photon=True`, not true (lower case), right? And are you sure you want to use `from ... import *`? I prefer the more explicit imports, like just `import sympy` so I don't mix up imported functions / classes with my own variables, functions etc. – FObersteiner Aug 17 '19 at 16:52
  • yes you are right, it should be True, thank you! –  Aug 18 '19 at 05:26

0 Answers0