Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ended up trying myself since the goal really was to do it 'hands off'. I'll leave the question open for a good while to see if anybody finds a better way.</p> <p>The code below uses bisection to bracket the points where <code>CountRoots</code> changes value. This works for my case (spotting the singularity at x=0 is pure luck):</p> <pre><code>In[214]:= findRootBranches[Function[x, Evaluate@geyvals[[1, 1]]], {-5, 5}] Out[214]= {{{-5., -0.0158768}, 1}, {{-0.0158768, -5.96046*10^-9}, 3}, {{0., 0.}, 2}, {{5.96046*10^-9, 1.05635}, 3}, {{1.05635, 5.}, 1}} </code></pre> <p>Implementation:</p> <pre><code>Options[findRootBranches] = { AccuracyGoal -&gt; $MachinePrecision/2, "SamplePoints" -&gt; 100}; findRootBranches::usage = "findRootBranches[f,{x0,x1}]: Find the the points in [x0,x1] \ where the number of real roots of a polynomial changes. Returns list of {&lt;interval&gt;,&lt;root count&gt;} pairs. f: Real -&gt; Polynomial as pure function, e.g f=Function[x,#^2-x&amp;]." ; findRootBranches[f_, {xa_, xb_}, OptionsPattern[]] := Module[ {bisect, y, rootCount, acc = 10^-OptionValue[AccuracyGoal]}, rootCount[x_] := {x, CountRoots[f[x][y], y]}; (* Define a ecursive bisector w/ automatic subdivision *) bisect[{{x1_, n1_}, {x2_, n2_}} /; Abs[x1 - x2] &gt; acc] := Module[{x3, n3}, {x3, n3} = rootCount[(x1 + x2)/2]; Which[ n1 == n3, bisect[{{x3, n3}, {x2, n2}}], n2 == n3, bisect[{{x1, n1}, {x3, n3}}], True, {bisect[{{x1, n1}, {x3, n3}}], bisect[{{x3, n3}, {x2, n2}}]}]]; (* Find initial brackets and bisect *) Module[{xn, samplepoints, brackets}, samplepoints = N@With[{sp = OptionValue["SamplePoints"]}, If[NumberQ[sp], xa + (xb - xa) Range[0, sp]/sp, Union[{xa, xb}, sp]]]; (* Start by counting roots at initial sample points *) xn = rootCount /@ samplepoints; (* Then, identify and refine the brackets *) brackets = Flatten[bisect /@ Cases[Partition[xn, 2, 1], {{_, a_}, {_, b_}} /; a != b]]; (* Reinclude the endpoints and partition into same-rootcount segments: *) With[{allpts = Join[{First@xn}, Flatten[brackets /. bisect -&gt; List, 2], {Last@xn}]}, {#1, Last[#2]} &amp; @@@ Transpose /@ Partition[allpts, 2] ]]] </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload