I am trying to find the solution of f[x,y]==0 by integrating along the curve starting from a point (vars1):
f[x_, y_] = y*(y^2 - x + 1);
vars = {x, y};
varsOt = Through[vars[t]];
vars1 = FindRoot[f[x, 0.5], {x, 0.5}]~Join~{y -> 0.5};
sysDAE0 = {(D[f[x, y], {{x, y}}] /. Thread[vars -> varsOt]).D[varsOt, t] == 0,
Norm[D[varsOt, t]] == 1, (varsOt /. t -> 0) == (vars /. vars1)};
{solx, soly} = NDSolveValue[sysDAE0, vars, {t, -3, 2},
Method -> {"EquationSimplification" -> "Residual"}];
Show[ContourPlot[f[x, y] == 0, {x, -.1, 2}, {y, -2, 2}, PlotPoints -> 100],
ParametricPlot[{solx[t], soly[t]}, {t, -3, 2}, AspectRatio -> 1/2,
PlotStyle -> Red]]
All the root curves are in blue, while the result of the above integration is in red:
Actually, I'd like to choose another branch; instead of take the right part of the $x$-axis, I'd like to catch the left part. To do so, I started by defining a function detecting the critical point (the norm of the gradient of f) in order to trigger WhenEvent. Then, I ask to choose a change the sign of x'[t] when the critical point is detected, hoping it would push the integration to the left of $(1,0)$. But it fails: the integration remains unchanged and still goes to the right of $(1,0)$. Any idea?
critical[x_, y_] = Norm[D[f[x, y], {{x, y}, 1}]];
{solx, soly} =
NDSolveValue[
sysDAE0~Join~{WhenEvent[critical[x[t], y[t]] < 10^-5,
x'[t] -> -x'[t]]}, vars, {t, -3, 2},
Method -> {"EquationSimplification" -> "Residual"}]
Edit To answer some of the comments, here is an example function, which requires the specified Method:
f[x_,y_] = y(9.77516 + 56.827 y^2 + 142.095 y^4 + x^2
(-31.1394 - 162.744 y^2 - 299.61 y^4) + x (9.88476 + 65.3474 y^2 + 180.768 y^4))
Running the NDSolveValue from above returns:
NDSolveValue::ntdv: Cannot solve to find an explicit formula for the derivatives.
Consider using the option Method->{"EquationSimplification"->"Residual"}.
Note that in that case, NDSolve computes the left branch... Then how can I get the right one (in a robust manner)?
Side notes on the equations I chose (answering to xzczd and Chris K's comments): I'd like to solve $f(x,y)=0$. Let's rewrite it $f(X)=0$ with $X=[x\ y]^\top$. Since I wanted to use the efficient NDSolve and the WhenEvent method and get an InterpolatingFunction, I instead looked for $t\mapsto X(t)$ such that $f(X(t))=0$. This implies that
$$\dfrac{\mathrm{d}}{\mathrm{d}t}f(X(t))=\nabla_X f(X(t))\cdot X'(t) = 0$$
for some initial conditions $X(0)$ such that $f(X(0))=0$. This gives one (differential) equation on $X$, so the system is undertermined; it can be completed with the following condition: $\|X'(t)\|=1$.



MaxStepFraction -> 0.00001gives a different solution. – Michael E2 Jan 30 '17 at 02:54WhenEvent? – anderstood Jan 30 '17 at 03:32f[x_, y_] =y*(y^2 - x + 1)-hand assignhto a small value. The closer you are to the bifurcation point the smallerhneeds to be. The estimate ish<<Abs[x - 1]^(3/2)(see 1. L. D. Landau and E. M. Lifshitz, Statistical Physics., 3 ed. Pergamon Press, Oxford, 1985, Chapter XIV, Section 144) – Alexei Boulbitch Jan 30 '17 at 09:28y'[t]==-y[t]*(y[t]^2 - x + 1), you will find that your desired solution of the algebraic equation represents a fixed point of this differential one. That is any solution will converge to those solutions that are stable. Atx<1these are+Sqrt(1-x)and-Sqrt(1-x). You may fix which of them will be chosen by the numerical process by choosing the initial condition, say,y[0]>0to choose the positive one ory[0]<0otherwise. – Alexei Boulbitch Jan 30 '17 at 09:41x=1as it should be (see E. M. Lifschitz and L. P. Pitajewski, Physikalische Kinetik. (1990), Chapter XII, Section 101) and the closer you are to this point, the longer must be the calculation time. – Alexei Boulbitch Jan 30 '17 at 09:41WhenEvent: I would think that at each stepx'[t]is calculated from the ODEs, so resetingx'[t], if it has any effect at all, has one only for one step. It's also possible that at no step is the norm less than10^-5(if the steps were too large). – Michael E2 Jan 30 '17 at 11:11PrintinWhenEvent, a possible work-around is to usecritical[x_, y_] = PiecewiseExpand[Norm[D[f[x, y], {{x, y}, 1}]], Reals]; With[{mid = D[critical[x[t], y[t]], t]},……WhenEvent[mid < 0,……instead. However this causes another problem, which I've no idea about the reason and how to resolve. – xzczd Jan 31 '17 at 03:47"EquationSimplification" -> "Residual"is unavoidable? – xzczd Jan 31 '17 at 03:54f[x, y]? – Chris K Feb 01 '17 at 12:23y? – Chris K Feb 02 '17 at 03:35yindeed). – anderstood Feb 02 '17 at 03:45ContourPlotapproach gives the right picture with no problem. Alternatively, you can get the answer analytically withSolve[f[x, y] == 0, y]. If you really want to follow each solution, I think they=0solution is distinct from the curvy "forks" in the pitchfork. Would you want to just numerically solve for the curvy forks? Because I have a technique for that. – Chris K Feb 02 '17 at 15:26InterpolatingFunctiongoing through the path I choose. I could join twoInterpolatingFunctionbut it leads to parametrisation issues. UsingSolvedoes not work on my real examples, becausefis really long. What's your trick to get the curvy forks? Dividing byy? – anderstood Feb 02 '17 at 15:33