Re: suggestions on how to do this
You could probably use scipy.base.polynomial, but it's easy enough to
implement a polynomial yourself. Just use a dict-- each key represents
the power and each value the coefficient of the polynomial.
You didn't say exactly how efficient you need this. It takes only a
couple seconds to sum 100 of the b(k)'s using the implementation below.
This gets you roots out to about A=500.
Perhaps there are bugs in the below implementation. Either way, you
can compare your results and its results and if they're not the same,
well then there's a problem.
--
from rational import rational #get from bitconjurer.org/rational.py
def add(a, b, s=1):
c = {}
for k, v in b.items():
if not a.has_key(k):
c[k] = s*v
for k, v in a.items():
vb = b.get(k, 0)
c[k] = a[k] + s*vb
return c
def raise1(a):
b = {}
for k, v in a.items():
b[k+1] = v
return b
def scale(a, s):
b = {}
for k, v in a.items():
b[k] = v*s
return b
def eval(x, p):
s = 0.0
for k, v in p.items():
s = s + float(v.num)/float(v.den)*x**k
return s
b = {-3 : {}, -2 : {}, -1 : {}, 0 : {0:rational(1,1)}, 1 : {}}
N = 100
for k in range(2,N):
b[k] = scale(raise1(add(b[k-5],b[k-2],-1)),rational(1,k**2))
o = [b[0]]
for k in range(1, N):
o.append(add(o[-1], b[k]))
for x in range(0,800):
print x, eval(x, o[-3]), eval(x, o[-2]), eval(x, o[-1])
# o[-1],o[-2], and o[-3] start to split around x = 500
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python Challenge ahead [NEW] for riddle lovers
pythonchallenge wrote: > For the riddles' lovers among you, you are most invited to take part > in the Python Challenge, the first python programming riddle on the net. > > You are invited to take part in it at: > http://www.pythonchallenge.com That was fun. The very first step in 6 was the most frustrating I thought. -- http://mail.python.org/mailman/listinfo/python-list
Re: array type casting problem in scipy.interpolate
The routine requires real arrays, and you are giving it one complex one. It does not know what to do with the complex array. What are you expecting it to do? If you need the real and imaginary parts to be separately interpolated, then split the complex array into two real arrays and use the routine twice. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on slow attribute copy
There's no way that loop takes fifteen minutes just because of the dot operator. I mean, 20 dots in 15 minutes is 200 dots/second. On a 1 GHz machine, that would be 5 million cycles per dot. That does not seem reasonable (assuming you haven't overridden the dot operator to do something more complicated than normal). Check that i.label does not have __hash__ overridden in a bad way. I tried a test case with __hash__ overridden to always return the same integer, and I got performance about what you are describing when I tried your example loop with 10 iterations. And, of course, make sure you are not low on memory and relying too heavily on swap space. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help on slow attribute copy
Hmm, it looks like the dot operator has been overloaded to do something complicated. (although if you haven't already, try "for i in nodes: pass" just to make sure). Is it retrieving the data from the network somewhere? If so, then it looks like it is probably retrieving each coordinate individually on each iteration of the loop. Perhaps there is some way of retrieving them all in one bunch? It's difficult to say more without knowing anything about abaqus and its interface. -- http://mail.python.org/mailman/listinfo/python-list
