Note that there are some explanatory texts on larger screens.

plurals
  1. POMathematica: branch points for real roots of polynomial
    primarykey
    data
    text
    <p>I am doing a brute force search for "gradient extremals" on the following example function</p> <pre><code>fv[{x_, y_}] = ((y - (x/4)^2)^2 + 1/(4 (1 + (x - 1)^2)))/2; </code></pre> <p>This involves finding the following zeros</p> <pre><code>gecond = With[{g = D[fv[{x, y}], {{x, y}}], h = D[fv[{x, y}], {{x, y}, 2}]}, g.RotationMatrix[Pi/2].h.g == 0] </code></pre> <p>Which <code>Reduce</code> happily does for me:</p> <pre><code>geyvals = y /. Cases[List@ToRules@Reduce[gecond, {x, y}], {y -&gt; _}]; </code></pre> <p><code>geyvals</code> is the three roots of a cubic polynomial, but the expression is a bit large to put here. </p> <p>Now to my question: For different values of <code>x</code>, different numbers of these roots are real, and I would like to pick out the values of <code>x</code> where the solutions branch in order to piece together the gradient extremals along the valley floor (of <code>fv</code>). In the present case, since the polynomial is only cubic, I could probably do it by hand -- but I am looking for a simple way of having Mathematica do it for me? </p> <p><strong>Edit</strong>: To clarify: The gradient extremals stuff is just background -- and a simple way to set up a hard problem. I am not so interested in the specific solution to this problem as in a general hand-off way of spotting the branch points for polynomial roots. Have added an answer below with a working approach. </p> <p><strong>Edit 2</strong>: Since it seems that the actual problem is much more fun than root branching: rcollyer suggests using <code>ContourPlot</code> directly on <code>gecond</code> to get the gradient extremals. To make this complete we need to separate valleys and ridges, which is done by looking at the eigenvalue of the Hessian perpendicular to the gradient. Putting a check for "valleynes" in as a <code>RegionFunction</code> we are left with only the valley line:</p> <pre><code>valleycond = With[{ g = D[fv[{x, y}], {{x, y}}], h = D[fv[{x, y}], {{x, y}, 2}]}, g.RotationMatrix[Pi/2].h.RotationMatrix[-Pi/2].g &gt;= 0]; gbuf["gevalley"]=ContourPlot[gecond // Evaluate, {x, -2, 4}, {y, -.5, 1.2}, RegionFunction -&gt; Function[{x, y}, Evaluate@valleycond], PlotPoints -&gt; 41]; </code></pre> <p>Which gives just the valley floor line. Including some contours and the saddle point:</p> <pre><code>fvSaddlept = {x, y} /. First@Solve[Thread[D[fv[{x, y}], {{x, y}}] == {0, 0}]] gbuf["contours"] = ContourPlot[fv[{x, y}], {x, -2, 4}, {y, -.7, 1.5}, PlotRange -&gt; {0, 1/2}, Contours -&gt; fv@fvSaddlept (Range[6]/3 - .01), PlotPoints -&gt; 41, AspectRatio -&gt; Automatic, ContourShading -&gt; None]; gbuf["saddle"] = Graphics[{Red, Point[fvSaddlept]}]; Show[gbuf /@ {"contours", "saddle", "gevalley"}] </code></pre> <p>We end up with a plot like this:</p> <p><img src="https://i.stack.imgur.com/J3mDy.png" alt="Contour plot of fv with the valley line superposed"></p>
    singulars
    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.
 

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