Raymond L. Buvel wrote:
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

Ray,

thanks a lot for your hint but I'm writing it for a students paper in a german math class so I believe I should better do some work alone ;-)

In addition I only need a class for polynomials and not for rational functions and I'm testing different iterative polynomial solvers. So I'm happy to have my own small class which I understand 100%.

Generally I'm against rediscovering the wheel again and again!

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

Reply via email to