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


Groups > comp.lang.python > #56654

Re: Debug (sympy-Function; lambdify)

From Marco Buttu <marco.buttu@gmail.com>
Newsgroups comp.lang.python
Subject Re: Debug (sympy-Function; lambdify)
Date 2013-10-11 08:50 +0200
Organization Aioe.org NNTP Server
Message-ID <l38735$1sg$3@speranza.aioe.org> (permalink)
References <ba477ba1-0813-409b-abe8-0e85c7d4ab5e@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

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

csiph-web