Skip to content
Advertisement

Precision for Python root function

I’m trying to approximate Julia sets using roots of polynomials in Python. In particular I want to find the roots of the nth iterate of the polynomial q(z) = z^2-0.5. In other words I want to find the roots of q(q(q(..))) composed n times. In order to get many sample points I would need to compute the roots of polynomials of degree >1000.

I’ve tried solving this problem using both the built in polynomial class of numpy which has a root function and also the function solver of sympy. In the first case precision is lost when I choose degrees larger than 100. The sympy computation simply takes to long time. Here is my code:

JavaScript

The max value above gives the largest value of p at a supposed root. However running this code gives me 7.881370400084486e+296 which is very large.

How would one go about computing roots of high degree polynomials with good accuracy in a short amount of time?

Advertisement

Answer

For the n-times composition of a polynomial q you can reconstruct the roots iteratively

JavaScript

which returns

JavaScript

or plotted

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement