Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #56652 > unrolled thread

Debug (sympy-Function; lambdify)

Started bySurbhi Gupta <surbhi.2388@gmail.com>
First post2013-10-10 23:28 -0700
Last post2013-10-11 08:50 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Debug (sympy-Function; lambdify) Surbhi Gupta <surbhi.2388@gmail.com> - 2013-10-10 23:28 -0700
    Re: Debug (sympy-Function; lambdify) Marco Buttu <marco.buttu@gmail.com> - 2013-10-11 08:50 +0200

#56652 — Debug (sympy-Function; lambdify)

FromSurbhi Gupta <surbhi.2388@gmail.com>
Date2013-10-10 23:28 -0700
SubjectDebug (sympy-Function; lambdify)
Message-ID<ba477ba1-0813-409b-abe8-0e85c7d4ab5e@googlegroups.com>
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?

[toc] | [next] | [standalone]


#56654

FromMarco Buttu <marco.buttu@gmail.com>
Date2013-10-11 08:50 +0200
Message-ID<l38735$1sg$3@speranza.aioe.org>
In reply to#56652
On 10/11/2013 08:28 AM, Surbhi Gupta wrote:

> 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?

There is just one error for me: array instead of np.array. Once changed 
this, it works fine (Python 3.3, SymPy 0.7.3)
-- 
Marco Buttu

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web