I search for brute force for “gradient extremals” in the following example function
fv[{x_, y_}] = ((y - (x/4)^2)^2 + 1/(4 (1 + (x - 1)^2)))/2;
This includes finding the next zeros
gecond = With[{g = D[fv[{x, y}], {{x, y}}], h = D[fv[{x, y}], {{x, y}, 2}]}, g.RotationMatrix[Pi/2].hg == 0]
Which Reduce happily does for me:
geyvals = y /. Cases[ List@ToRules @Reduce[gecond, {x, y}], {y -> _}];
geyvals are the three roots of the cubic polynomial, but the expression here is a little large.
Now to my question: for different values of x different numbers of these roots are valid, and I would like to highlight the values of x , where are the decision branches in order to compose the gradient extremals along the valley floor ( fv ). In this case, since the polynomial is only cubic, I could do it manually - but am I looking for an easy way to get Mathematica to do this for me?
Change To clarify: the material of gradient extremals is just a background - and an easy way to fix a complex problem. I am not interested in a specific solution to this problem, as in the general method for determining branch points for polynomial roots. Added the answer below with a working approach.
Change 2 . Since it seems that the actual problem is much more interesting than root branching: rcollyer suggests using ContourPlot directly on gecond to get extreme gradients. To do this completely, we need to separate the valleys and ridges, which is done by looking at the eigenvalue of the Hessian perpendicular to the gradient. Putting a check on "valleynes" as a RegionFunction , we only stay with the valley line:
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 >= 0]; gbuf["gevalley"]=ContourPlot[gecond // Evaluate, {x, -2, 4}, {y, -.5, 1.2}, RegionFunction -> Function[{x, y}, Evaluate@valleycond ], PlotPoints -> 41];
This gives only the valley floor line. Including some contours and a saddle point:
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 -> {0, 1/2}, Contours -> fv@fvSaddlept (Range[6]/3 - .01), PlotPoints -> 41, AspectRatio -> Automatic, ContourShading -> None]; gbuf["saddle"] = Graphics[{Red, Point[fvSaddlept]}]; Show[gbuf /@ {"contours", "saddle", "gevalley"}]
The result is the following plot:
