any Python equivalent of Math::Polynomial::Solve?
Just
just at xs4all.nl
Sun Feb 27 05:10:31 EST 2005
In article <1109485184.587035.176540 at l41g2000cwc.googlegroups.com>,
"Carl Banks" <invalidemail at aerojockey.com> wrote:
> Just wrote:
> > While googling for a non-linear equation solver, I found
> > Math::Polynomial::Solve in CPAN. It seems a great little module,
> except
> > it's not Python... I'm especially looking for its poly_root()
> > functionality (which solves arbitrary polynomials). Does anyone know
> of
> > a Python module/package that implements that?
>
> If you don't have a great need for speed, you can accomplish this
> easily with the linear algebra module of Numeric/numarray. Suppose
> your quintic polynomial's in the form
>
> a + b*x + c*x**2 + d*x**3 + e*x**4 + x**5
>
> The roots of it are equal to the eigenvalues of the companion matrix:
>
> 0 1 0 0 0
> 0 0 1 0 0
> 0 0 0 1 0
> 0 0 0 0 1
> -a -b -c -d -e
>
> It should be pretty easy to set up a Numeric matrix and call
> LinearAlgebra.eigenvalues. For example, here is a simple quintic
> solver:
>
> . from Numeric import *
> . from LinearAlgebra import *
> .
> . def quinticroots(p):
> . cm = zeros((5,5),Float32)
> . cm[0,1] = cm[1,2] = cm[2,3] = cm[3,4] = 1.0
> . cm[4,0] = -p[0]
> . cm[4,1] = -p[1]
> . cm[4,2] = -p[2]
> . cm[4,3] = -p[3]
> . cm[4,4] = -p[4]
> . return eigenvalues(cm)
>
>
> now-you-can-find-all-five-Lagrange-points-ly yr's,
Wow, THANKS. This was the answer I was secretly hoping for... "Great
need for speed", no, not really, but this Numeric-based version is about
9 times faster than what I translated from Perl code yesterday, so from
where I'm standing your version is blazingly fast...
Thanks again,
Just
More information about the Python-list
mailing list