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

2014-07-12 Thread Chris Angelico
On Sat, Jul 12, 2014 at 3:33 AM, Niklas Troedsson
niklastroeds...@yahoo.com.dmarc.invalid wrote:
 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.


This is a general Python list, not Canopy or Sympy specific. If you
don't get a useful response here, you may want to try looking for
their mailing lists; Canopy appears to be (sorry, I'm not familiar
with it) an Enthought package, so you could ask Enthought for support;
and Sympy doubtless has its own lists, which you could find with a
Google search. I suspect that what you're asking about may be
sufficiently specialized that you'll get better responses there.

But you might get a response here. Never know! We do have some pretty
awesome experts on python-list.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


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

2014-07-11 Thread Niklas Troedsson
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()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