any Python equivalent of Math::Polynomial::Solve?
Cousin Stanley
CousinStanley at HotMail.Com
Tue Mar 1 18:08:31 CET 2005
Alex ....
Thanks for posting your generalized numarray
eigenvalue solution ....
It's been almost 30 years since I've looked at
any characteristic equation, eigenvalue, eignevector
type of processing and at this point I don't recall
many of the particulars ....
Not being sure about the nature of the monic( p ) function,
I implemented it as an element-wise division of each
of the coefficients ....
Is this anywhere near the correct interpretation
for monic( p ) ?
Using the version below, Python complained
about the line ....
. M[ -1 , : ] = -p[ : -1 ]
So, in view of you comments about slicing in you follow-up,
I tried without the slicing on the right ....
. . M[ -1 , : ] = -p[ -1 ]
The following code will run and produce results,
but I'm wondering if I've totally screwed it up
since the results I obtain are different from
those obtained from the specific 5th order Numeric
solution previously posted here ....
. from numarray import *
.
. import numarray.linear_algebra as LA
.
. def monic( this_list ) :
.
. m = [ ]
.
. last_item = this_list[ -1 ]
.
. for this_item in this_list :
.
. m.append( this_item / last_item )
.
. return m
.
.
. def roots( p ) :
.
. p = monic( p )
.
. n = len( p ) # degree of polynomial
.
. z = zeros( ( n , n ) )
.
. M = asarray( z , typecode = 'f8' ) # typecode = c16, complex
.
. M[ : -1 , 1 : ] = identity( n - 1 )
.
. M[ -1 , : ] = -p[ -1 ] # removed : slicing on the right
.
. return LA.eigenvalues( M )
.
.
. coeff = [ 1. , 3. , 5. , 7. , 9. ]
.
. print ' Coefficients ..'
. print
. print ' %s' % coeff
. print
. print ' Eigen Values .. '
. print
.
. eigen_values = roots( coeff )
.
. for this_value in eigen_values :
.
. print ' %s' % this_value
.
Any clues would be greatly appreciated ....
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list