I am now using Symbol and Function where the name and the value match. That 
was recommended for easier reading and then required for pickle. In order 
to avoid confusing these, I have a different name for Symbol and for 
Function, then I convert them just before printing. My problem is that I am 
not sure how to use this when I take derivatives. When I look at q1S in the 
debugger I see it has type Symbol, but q1F has value q1F(t) and type Q1F 
(not Function).
The code looks like this:
def createSymbols():
    global t, q1S, q2S, q1F, q2F, q1dotS, q2dotS, q1ddotS, q2ddotS
    t = symbols('t')
    q1S, q2S = symbols('q1S, q2S')
    q1dotS, q2dotS = symbols('q1dotS, q2dotS')
    q1ddotS, q2ddotS = symbols('q1ddotS, q2ddotS')
    q1F = Function('q1F')(t)
    q2F = Function('q2F')(t)
    print('end of createSymbols HillCusp')

def symForLatex(expIn):
    expOut = expIn
    expOut = expOut.subs(q1S, symbols('q1'))
    expOut = expOut.subs(q2S, symbols('q2'))
    expOut = expOut.subs(q1F, symbols('q1'))
    expOut = expOut.subs(q2F, symbols('q2'))
    expOut = expOut.subs(q1dotS, symbols('{\dot{q}}_{1}'))
    expOut = expOut.subs(q2dotS, symbols('{\dot{q}}_{2}'))
    expOut = expOut.subs(q1ddotS, symbols('{\ddot{q}}_{1}'))
    expOut = expOut.subs(q2ddotS, symbols('{\ddot{q}}_{2}'))
    return expOut

Here is the code that calculates higher-order derivatives. The second-order 
derivative is defined by Newton's equations (ODEs).
    if qi == 1:
        if nDer == 0:
            retVal = q1F#(t)
        elif nDer == 1:
            retVal = diff(qd(1, 0), t)
        elif nDer == 2:
            retVal = 2*qd(2, 1) + 3*qd(1, 0) - qd(1, 0)*(qd(1, 0)**2 + 
qd(2, 0)**2)**Rational(-3,2)
        else:
            retVal = diff(qd(1, nDer-1), t)
            # replace q1dd & q2dd
            #retVal = retVal.subs(Derivative(q1F(t), (t, 2)), qd(1, 2))
            #retVal = retVal.subs(Derivative(q2F(t), (t, 2)), qd(2, 2))
            retVal = retVal.subs(Derivative(q1F, (t, 2)), qd(1, 2))
            retVal = retVal.subs(Derivative(q2F, (t, 2)), qd(2, 2))

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/4f674d25-e795-432e-8ea4-a116005e8dbdn%40googlegroups.com.

Reply via email to