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


Groups > comp.lang.python > #74361

Error after sympy lambdify function update using vector() dot.class

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <niklastroedsson@yahoo.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python.': 0.02; 'syntax': 0.04; 'filename:fname piece:py': 0.07; 'subject:Error': 0.07; 'variables': 0.07; 'subject:update': 0.09; 'subject:using': 0.09; 'true)': 0.09; 'worked.': 0.09; '###': 0.16; 'lambda': 0.16; 'numpy': 0.16; 'pylab': 0.16; 'received:173.164': 0.16; 'renaming': 0.16; 'skip:n 50': 0.16; 'subject:after': 0.16; 'substitute': 0.16; 'syntaxerror:': 0.16; 'fix': 0.17; 'variable': 0.18; 'programming': 0.22; 'import': 0.22; 'to:name:python- list@python.org': 0.22; 'error': 0.23; 'copied': 0.24; 'earlier': 0.24; 'header:Received:8': 0.24; 'versions': 0.24; 'updating': 0.26; 'pass': 0.26; 'code:': 0.26; 'function': 0.29; 'points': 0.29; 'skip:( 20': 0.30; 'gives': 0.31; 'code': 0.31; '"",': 0.31; 'file': 0.32; 'class': 0.32; 'worked': 0.33; 'updated': 0.34; 'problem': 0.35; 'anybody': 0.35; 'but': 0.35; 'version': 0.36; 'shows': 0.36; 'changing': 0.37; 'thank': 0.38; 'manager': 0.38; 'stopped': 0.38; 'to:addr:python-list': 0.38; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'above,': 0.60; 'received:98.137': 0.60; 'solve': 0.60; 'forum': 0.61; 'new': 0.61; 'received:173': 0.61; 'such': 0.63; 'skip:n 10': 0.64; 'more': 0.64; 'header:Reply-To:1': 0.67; 'invalid': 0.68; 'received:gq1.yahoo.com': 0.68; 'received:mail.gq1.yahoo.com': 0.68; 'received:98.136': 0.69; 'below.': 0.71; '8bit%:100': 0.72; 'skip:a 40': 0.72; 'transfer': 0.82; 'equation,': 0.84; 'received:bullet.mail.gq1.yahoo.com': 0.84
X-Yahoo-Newman-Property ymail-4
X-Yahoo-Newman-Id 35753.90997.bm@omp1075.mail.gq1.yahoo.com
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1405099994; bh=ylVvrZVnhGMslNa6UAEWxIWjep/h3LTMTM3ebZRMOA8=; h=Message-ID:Date:From:Reply-To:Subject:To:MIME-Version:Content-Type; b=e8ygFRMEW8SSDWaYG7pwi22yNR2hSYBvQX23ZFSIO5pdLF8Cn8xqOHstVJ8o5NUQ//TGtLkIOdyYZlloGW1JsVfdPqfBFZ1tigV/j3sp4iv9TiTlypZjgcUKEgK8ktoRzqiXe8FEeMzHE+BiSxFzr2AidC/I+qkjjD3V5+wSJCk=
X-YMail-OSG XQxMNtAVM1kwCpD_TdVl8B4IA1QytnC6C0znNhHck_QKOit 8sG2vKN3yzPfCpH1sx.bHuqVX7DTCvyaktd0QNd5G2gHrq18XQGKzMGy.wVN 09kj3GmsHSISiFN2wPX7vCMZUccGFfUeRqZmV6GQjM9gv1MB8Ml74rbU4.hf WH.G9xQ5m0_nKyGqKaIAiUkXtl3ULdM6lMFcdrLQNZ0uoTVXBuYavuevVpiv 7ZrPTyx54RwyaFySjNZrxidgGRAid7oAJnRaeg8XX2ETXTEn.cor6ncNzKNS E2QN1j2oK_5TQ7Ucgp9Z5SStC2yAXr2dicEdmezNH.e3L1iKQK5L0WAE.j_S ZZihHePIrKJ_ucS92xT73rAjkj8pnLZyqORc2iWq7XJcALAuSBE02LcrrOYK R.URYmDhjbOjPW8GJkXXU9z1Vrr9m0NGalq_tTCWYgLwZUs4AYjHj9nTFrKF RlVCdbPo4v_loYnYjFclgZHg1B7V96yo6xPMTvme6uIP8CqoK0LDJ7BVMEHr 2GHVF2M774jbphTZd5S9yNnd6RPzbGe21VLlwQl5STlTDiM.l3xwRpkJy1lA K_VXpDGsPZZwISys56rYw6tjdEZx4Lf7N8QAOvOtvdrdiO7flv6GAVLgF8QV IjIZ9GNvvtk2Ep1MG5tolihOPfXHSYVgcqcEMYPMYJuNh
X-Rocket-MIMEInfo 002.001, SSBhbSBuZXcgdG8gdGhlIGZvcnVtIGFuZCBwcm9ncmFtbWluZyBQeXRob24uCgpSZWNlbnRseSBJIHVwZGF0ZWQgYm90aCBDYW5vcHkgYW5kIGl0cyBwYWNrYWdlcywgSSBhbSBub3cgdXNpbmcgQ2Fub3B5IDEuNC4xLjE5NzUgYW5kIHN5bXB5IDAuNy41LTEuCgpJbiBhbiBlYXJsaWVyIHZlcnNpb24gbXkgY29kZSB0byBzb2x2ZSBhbGdlYnJhIGFuZCBzdWJzdGl0dXRlIGEgbG90IG9mIGNvbnN0YW50cyBhbmQgdHJhbnNmZXIgZnVuY3Rpb25zIHdpdGggbW9yZSB0aGFuIDEwMDEgZnJlcXVlbmN5IHBvaW50cyABMAEBAQE-
X-Mailer YahooMailWebService/0.8.194.680
Date Fri, 11 Jul 2014 10:33:14 -0700
From Niklas Troedsson <niklastroedsson@yahoo.com>
Subject Error after sympy lambdify function update using vector() dot.class
To "python-list@python.org" <python-list@python.org>
MIME-Version 1.0
Content-Type multipart/mixed; boundary="-432529009-1483969506-1405099994=:42214"
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To Niklas Troedsson <niklastroedsson@yahoo.com>
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11764.1405100802.18130.python-list@python.org> (permalink)
Lines 400
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1405100802 news.xs4all.nl 2938 [2001:888:2000:d::a6]:38543
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:74361

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

I am new to the forum and programming Python.

Recently I updated both Canopy and its packages, I am now using Canopy 1.4.1.1975 and sympy 0.7.5-1.

In an earlier version my code to solve algebra and substitute a lot of constants and transfer functions with more than 1001 frequency points worked. But after the package update to the versions above, lambdify function stopped working and shows an invalid syntax error, pointing to the "dot" in alg.const1.

Can anybody help to get around this without changing the original code of using alg.const1, instead of the cumbersome fix of renaming all variables and make them single variable names such as alg_const1.

%run testofdotclasslambdify.py
  File "<string>", line 1
    lambda alg.npnt1,alg.npnt2,alg.ntf1,alg.const1: (alg.const1*(alg.npnt2 + alg.ntf1)/(alg.const1 + alg.npnt2 + alg.ntf1))
              ^
SyntaxError: invalid syntax
 
I have attached the *.py code and copied in below.

Thank you!

testofdotclasslambdify.py
.

import numpy as np
import pylab as pl
import sympy as sy

# empty class for variables
class vector:
pass
#

# frequency, radians and Laplace representation
fqaxst = 1.0e2
fqaxsp = 100.0e6
fqnop  = 1001
fq     = np.logspace(np.log10(fqaxst),np.log10(fqaxsp),fqnop)
wq     = 2*np.pi*fq
s      = 1.0j*wq

ntf1   = np.exp(-s*1.0/10e6)

npnt1  = 1
npnt2  = 1
const1 = 1

### solve #1 with lambdify 
#   set equation, variables and constants to solve
alg_phiout, alg_npnt1, alg_npnt2 = sy.symbols('alg_phiout, alg_npnt1, alg_npnt2')
alg_ntf1, alg_const1             = sy.symbols('alg_ntf1, alg_const1', complex = True)

subst1       = (alg_npnt1, alg_npnt2, alg_ntf1, alg_const1)

sol          = vector() 
sol.algnpnt1 = (alg_npnt1-alg_phiout/alg_const1)*(alg_ntf1+alg_npnt2)-alg_phiout
sol.solnpnt1 = sy.simplify(sy.diff(sy.solve(sol.algnpnt1, alg_phiout)[0], alg_npnt1,1))
sol.refnum1  = sy.lambdify(subst1, sol.solnpnt1)
tf1          = sol.refnum1(npnt1, npnt2, ntf1, const1)

# plot
pl.figure(1)
pl.semilogx(fq,10*np.log10(np.abs(tf1)**2),label='tf1')
pl.legend(loc='lower right')
pl.title('TF')
pl.xlabel('Frequency, Hz')
pl.ylabel('Spectrum, dB')
pl.grid(b='on')
pl.show()

### solve #2 with lambdify using vector as dot-class variables
#   problem with code below, which wasn't a probelm before updating Canopy package manager 2014-July-01
#   I do not want all variables as signle variables but bundled in a vector dot.class

# set equation, variables and constants to solve
alg = vector()

alg.phiout, alg.npnt1, alg.npnt2 = sy.symbols('alg.phiout, alg.npnt1, alg.npnt2')
alg.ntf1, alg.const1             = sy.symbols('alg.ntf1, alg.const1', complex = True)

subst2       = (alg.npnt1, alg.npnt2, alg.ntf1, alg.const1)
sol.algnpnt2 = (alg.npnt1-alg.phiout/alg.const1)*(alg.ntf1+alg.npnt2)-alg.phiout
sol.solnpnt2 = sy.simplify(sy.diff(sy.solve(sol.algnpnt2, alg.phiout)[0], alg.npnt1,1))
sol.refnum2  = sy.lambdify(subst2, sol.solnpnt2)

# problem with new version of lambdify in new sympy, old version of lambdify/sympy worked
# Gives the following error code:
tf2          = sol.refnum2(npnt1, npnt2, ntf1, const1)
# tf2        = sol.refnum2(npnt1, npnt2, ntf1, const1)
#   In [10]: %run testofdotclasslambdify.py
#    File "<string>", line 1
#      lambda alg.npnt1,alg.npnt2,alg.ntf1,alg.const1: (alg.const1*(alg.npnt2 + alg.ntf1)/(alg.const1 + alg.npnt2 + alg.ntf1))
#               ^
#   SyntaxError: invalid syntax
# In [11]:

# plot
pl.figure(2)
pl.semilogx(fq,10*np.log10(np.abs(tf1)**2),label='tf1')
pl.legend(loc='lower right')
pl.title('TF')
pl.xlabel('Frequency, Hz')
pl.ylabel('Spectrum, dB')
pl.grid(b='on')
pl.show()

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


Thread

Error after sympy lambdify function update using vector() dot.class Niklas Troedsson <niklastroedsson@yahoo.com> - 2014-07-11 10:33 -0700

csiph-web