Debug (sympy-Function; lambdify)

Surbhi Gupta surbhi.2388 at gmail.com
Fri Oct 11 02:28:10 EDT 2013


This is the code I m trying to run:

from sympy import *
import numpy as np
from sympy import symbols

def deriv(x,t):
    a = array(x)
    for i in range(0,len(x)):
        temp = x[i]
        a[i] = temp[0].diff(t)
    return a

def matrixmult (A, B):
    C = [[0 for row in range(len(A))] for col in range(len(B[0]))]
    for i in range(len(A)):
        for j in range(len(B[0])):
            for k in range(len(B)):
                C[i][j] += A[i][k]*B[k][j]
    return C

l1,l2,m1,m2,t = symbols('l1,l2,m1,m2,t')
g = 10

th1 = Function('th1')(t)
th2 = Function('th2')(t)
th1dot = Derivative(th1, t)
th2dot = Derivative(th2, t)

x1 = array([[l1*sin(th1)], [-l1*cos(th1)]])
x2 = x1 + array([[l2*sin(th1 + th2)], [-l2*cos(th1 + th2)]])
x1dot = deriv(x1, t)
x2dot = x1dot + deriv(x2, t)

temp1 = matrixmult(x1dot.T,x1dot)
temp2 = matrixmult(x2dot.T, x2dot)
kin = (1/2.0)*m1*temp1[0][0] + (1/2.0)*m2*temp2[0][0]
pot = -m1*g*l1*cos(th1) -m2*g*(l1*cos(th1) + l2*cos(th1+th2))
L = kin - pot
 
e = lambdify((t, l1, l2, m1, m2, th1, th2), L)


all other commands of above code run with no error. but as soon as I give last command (the lambdify 1) I get a syntax error. I think that is because I m using th1 and th2 as Function of t. Can anyone help me on how to solve this?



More information about the Python-list mailing list