how to find intersection between a parametric trajectoy and a point - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-18T05:54:20Z https://mathematica.stackexchange.com/feeds/question/55039 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/55039 2 how to find intersection between a parametric trajectoy and a point Mike84 https://mathematica.stackexchange.com/users/12437 2014-07-16T17:28:33Z 2014-07-17T13:03:10Z <p>I'have a 2d-system of differential equations, analitycally solved, depending on a parameter. I know that, by continuity, there exist a minimum value of the parameter such that trajectory passes through a specific point. My problem is to find such value (also approximatively).</p> <p>This is the system-equation:</p> <pre><code>ti = 0; yi = 0; zi = -.75; zf = -.5; eps=.01; sol = FullSimplify[DSolve[{y'[t] == 1/(2 zf) y[t] - u z[t], z'[t] == -1 + 1/zf z[t] + u y[t], y[ti] == yi, z[ti] == zi},{y[t],z[t]},t]]; </code></pre> <p>The parameter is u.</p> <p>I have to find the first u such that trajectorie intersect the point: z=zf; y=Sqrt[-2*(zf)*eps + eps^2]</p> <p>Note that this point is done by the intersection between <code>z=zf</code> and the circle of radius <code>|zf|+eps</code>. In the following, you can see an animation of the system:</p> <pre><code>Manipulate[ Module[{sol, y, z, t}, sol = First@DSolve[{y'[t] == 1/(2 zf) y[t] - u z[t], z'[t] == -1 + 1/zf z[t] + u y[t], y[ti] == yi, z[ti] == zi}, {y[t], z[t]}, t]; Show[p1, p2, Graphics[{Red, Line[{{0, -1}, {0, 1}}]}], Graphics[{DotDashed, Red, Thickness[.006], Line[{{-1, zf}, {1, zf}}]}], ParametricPlot[{y[t] /. sol, z[t] /. sol}, {t, 0, tend}, PlotStyle -&gt; Thickness[.004]]]], {{tend, .1, "t"}, .01, 20, .1, Appearance -&gt; "Labeled"}, {{u, 10, "u"}, -300, 300, .5, Appearance -&gt; "Labeled"}, {{zi, -.75, "zi"}, -1, 1, Appearance -&gt; "Labeled"}, {{yi, 0, "yi"}, -1, 1, Appearance -&gt; "Labeled"}, Initialization :&gt; (deltaA[y_, z_] := 1/(2 zf) y^2 - z + 1/zf z^2; circ[y_, z_] := y^2 + z^2; p2 = ContourPlot[{circ[y, z] == (-zf + eps)^2}, {y, -1, 1}, {z, -1, 1}, ContourStyle -&gt; Yellow, GridLines -&gt; Automatic, Frame -&gt; True, FrameLabel -&gt; {"y", "z"}, RotateLabel -&gt; False, LabelStyle -&gt; {FontSize -&gt; 20}]; p1 = ContourPlot[{deltaA[y, z] == 0}, {y, -1, 1}, {z, -1, 1}, ContourStyle -&gt; Green, GridLines -&gt; Automatic, Frame -&gt; True, FrameLabel -&gt; {"y", "z"}, RotateLabel -&gt; False, LabelStyle -&gt; {FontSize -&gt; 20}];)] </code></pre> https://mathematica.stackexchange.com/questions/55039/-/55053#55053 2 Answer by george2079 for how to find intersection between a parametric trajectoy and a point george2079 https://mathematica.stackexchange.com/users/2079 2014-07-16T20:11:27Z 2014-07-17T13:03:10Z <p>Here is a stab at what I think you are asking:</p> <pre><code> ti = 0; yi = 0; zi = -.75; zf = -.5; eps = .01; sol = {y[t], z[t]} /. First@FullSimplify[DSolve[{ y'[t] == 1/(2 zf) y[t] - u z[t], z'[t] == -1 + 1/zf z[t] + u y[t], y[ti] == yi, z[ti] == zi}, {y[t], z[t]}, t]]; target = {Sqrt[-2*(zf)*eps + eps^2], zf}; </code></pre> <p>brute force discretize the solution and find the minimum distance to the target point (for such a highly nonlinear function this is much faster than <code>NMinimise</code>, and guarantees finding a global min, within the discretization approximation of course )</p> <pre><code> dis[u0_] := Min@Table[Norm[ (sol /. u -&gt; u0) - target ] , {t, 0, 10, .05}]; </code></pre> <p>note the range and increment on <code>t</code> here are important tuning parameters to play with.</p> <pre><code> Plot[dis[u], {u, -1, 1}] </code></pre> <p><img src="https://i.stack.imgur.com/bmzeQ.png" alt="enter image description here"></p> <p>you come very close to your target point around 0.21.</p> <p>Armed with a good guess now we can use <code>FindMinimum</code>:</p> <pre><code> FindMinimum[Norm[sol - target], {u, .21 } , {t, 1}] </code></pre> <blockquote> <p>{3.23748*10^-9, {u -> 0.230625, t -> 1.62219}}</p> </blockquote> <pre><code> ParametricPlot[ Table[Chop[sol /. u -&gt; u0 ], {u0, {.1, .230625, .3, 1, 5}}] , {t, 0, 10}, Epilog -&gt; Point[target], PlotRange -&gt; All, AspectRatio -&gt; 1] </code></pre> <p><img src="https://i.stack.imgur.com/sUyTY.png" alt="enter image description here"></p>