1
$\begingroup$

Consider the following plot of and ODE solution in phase space ( the code is written below). The red curve is the parametric plot of the solution in phase space, and the blue line is a given curve (in this simplified case, a straight line).

enter image description here

f[x_, y_] := -x + 0.1 y + x^2 y; 
g[x_, y_] := 0.5 - 0.1 y - x^2 y; 
sol = NDSolve[{x'[t] == f[x[t], y[t]], y'[t] == g[x[t], y[t]], 
    x[0] == 0.6, y[0] == 1.4}, {x, y}, {t, 0, 300}];
Show[StreamPlot[{f[x, y], g[x, y]}, {x, 0, 1}, {y, 0.5, 2}, 
  StreamStyle -> Black],
 ParametricPlot[{Evaluate[x[t]], Evaluate[y[t]]} /. sol, {t, 0, 100}, 
  PlotStyle -> Red],
 ParametricPlot[{0.5, y}, {y, 0.5, 2}, PlotStyle -> Blue]]

How can I extract from the solution the intersections of the red curve and the blue line?

i.e, both a list of the position of the intersection and the time between the intersections.

$\endgroup$
3
$\begingroup$

Just solve t for x[t]==1/2 with 0<t<100, and plot the points. Here, rulesgives you the time, and pointsthe intersections:

eqs = Flatten@({x[t], y[t]} /. sol);
rules = FindInstance[eqs[[1]] == 1/2 && 0 < t < 100, {t}, 30];
points = DeleteDuplicates[(eqs /. #) & /@ rules];

Show[StreamPlot[{f[x, y], g[x, y]}, {x, 0, 1}, {y, 0.5, 2}, 
StreamStyle -> Black], 
ParametricPlot[{Evaluate[x[t]], Evaluate[y[t]]} /. sol, {t, 0, 100}, PlotStyle -> Red], 
ParametricPlot[{0.5, y}, {y, 0.5, 2}, PlotStyle -> Blue], 
ListPlot[points, PlotStyle -> Green]]

enter image description here

$\endgroup$
  • $\begingroup$ I'll accept this answer if it will be generalized to any given curve (not just a line). $\endgroup$ – jarhead Apr 29 '18 at 13:31
  • $\begingroup$ Also, what is the meaning of "30" at the FindInstances command? $\endgroup$ – jarhead Apr 29 '18 at 13:44
  • 1
    $\begingroup$ @jarhead See the docs of FindInstance. And this post is a direct answer to your question, so it would be rude not to accept it, especially that you've already asked another, more general, question. $\endgroup$ – corey979 Apr 29 '18 at 16:39
  • $\begingroup$ @jarhead in a hurry, “30” in FindInstances is how many instances you want when solving the equation. If you want more than existing, you will obtain duplicates. On the other hand, as @corey979 says, you look for a solution of a intersecting line, not a general curve. BTW, this curve is closed or open?, in parametric, implicit, or explicit form? $\endgroup$ – José Antonio Díaz Navas Apr 29 '18 at 17:24
  • 2
    $\begingroup$ @JoséAntonioDíazNavas, I accepted your answer, as it adressed the questions, but have a look at a more generalized solution at mathematica.stackexchange.com/questions/172205/… $\endgroup$ – jarhead Apr 29 '18 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.