I need to find the roots of a rational polynomial that are near i. In the following code, I try that two different ways. First, I use a constraint to only find roots in the right region. Second, I find all the roots and discard the ones not in the right region. Surprisingly, the second, wasteful method is much faster. Why?
z[0, c_] := c
z[n_, c_] := z[n - 1, c]^2 + c;
r = 1/10;
prec = 10;
expr = Expand[z[10, c] - z[6, c]];
Print[Timing[aa = c /. N[Solve[{expr == 0, Abs[c - I] < r}, c], prec];]];
Print[Timing[bb = Select[c /. N[Solve[expr == 0, c], prec], Abs[# - I] <= r &];]];
(* {4365.47,Null} {176.39,Null} *)
Clearly Solve[]
is doing something terribly inefficient in its handling of constraints. I know I could use FindRoots[]
to find roots one at a time and divide them out of the polynomial, then I wouldn't know when I'd found all the roots in the region and could stop looking. But when I tried that, I ran into this problem.
So how can I efficiently find all the roots within radius r of i?
And what the heck is going with Solve[]
?
SolveValues[…, c]
(instead ofc /. Solve[…]
)? $\endgroup$