Thanks! This puts me on the road again :)

That is a great tutorial... I looked at the all_coeffs() option
before, but could get it to work, probably because of the data types
you explain.

I guess it's time that I take a look at the numerical methods courses
from my college years.

Thanks.

Regards, anartz

On Aug 16, 2:04 am, smichr <[email protected]> wrote:
> > > Second Variant (using Poly) kind of works, but there is a small fix
> > > required. "mypoly.coeffs" ommits the zeros, therefore if the
> > > coefficients for x^0, x^1 and x^3 are 0, they would not appear. Is
> > > this a bug or a feature?
>
> [cut]
>
> > Now there must be a better way to do this [...to get the coefficients of a 
> > polynomial]
>
> In interactive mode, if you do
>
> >>> help(mypoly)
>
> you will receive the documentation about polynomials included in
> sympy. If you browse through that you will see there is a method
> called .iter_all_coeffs() and that is the one that you want to get ALL
> the coefficients, even the zeros:
>
> >>> list(mymonic.iter_all_coeffs())
>
> [1, 2.32000000000000, -126.654400000000, 0, 118.147448015123, 0, 0]
>
> Right now, if you try to pass this directly to polyroots it will
> complain because you are sending sympy numbers, but if you change them
> all to floats first it works. Here it is step by step:
>
> When you use the iter_all_coeffs() method, you get a generator...>>> 
> mymonic.iter_all_coeffs()
>
> <generator object iter_all_coeffs at 0x01FF3968>
>
> but polyroots needs a real list of numbers not the thing that can
> *make* the list so...>>> list(_)
>
> [1, 2.32000000000000, -126.654400000000, 0, 118.147448015123, 0, 0]
>
> Now, if you *copied* and pasted those numbers they would work, but if
> you tried polyroots(list(mymonic.iter_all_coeffs())) it would fail
> because then you are sending the *sympy numbers* directly and right
> now polyroots is not ready to handle that. The solution is to turn
> them into floating point numbers first:
>
> >>> [float(tmp) for tmp in mo.iter_all_coeffs()]
>
> [1.0, 2.3199999999999998, -126.6544, 0.0, 118.147448015123, 0.0, 0.0]
>
> Putting it all together gives...>>> mpmath.polyroots([float(tmp) for tmp in 
> mymonic.iter_all_coeffs()])
>
> [mpf('-12.439917313666234'), mpf('-0.96089172423224767'), mpf
> ('-9.5259289164838849e-19'), mpf('5.8873478448024993e-19'), mpf
> ('0.97837756504691176'), mpf('10.102431472851569')]
>
> /c
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to