Alex Renelt wrote:
Alex Renelt wrote:

in addition:
I'm writing a class for polynomial manipulation. The generalization of the above code is:


definitions:
1.) p = array([a_0, a_i, ..., a_n]) represents your polynomial
P(x) = \sum _{i=0} ^n a_i x^i

2.) deg(p) is its degree

3.) monic(p) makes P monic, i.e. monic(p) = p / p[:-1]

then you get:
from numarray import *
import numarray.linear_algebra as la

def roots(p):
    p = monic(p); n = deg(p)
    M = asarray(zeros((n,n)), typecode = 'f8')
# or 'c16' if you need complex coefficients
    M[:-1,1:] = identity(n-1)
    M[-1,:] = -p[:-1]
    return la.eigenvalues(M)

Alex


uhh, I made a mistake:
under definitions, 3.)
its "monic(p) = p / p[-1]" of course

Alex

Alex,

If you want a class for polynomial manipulation, you should check out my ratfun module.

http://calcrpnpy.sourceforge.net/ratfun.html

Ray
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to