Re: Terminate NDSolve by a condition
- To: mathgroup at smc.vnet.net
- Subject: [mg123622] Re: Terminate NDSolve by a condition
- From: Bob Hanlon <hanlonr357 at gmail.com>
- Date: Tue, 13 Dec 2011 05:42:48 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201112121142.GAA12764@smc.vnet.net>
eqns = {x'[t] == -Sin[t], y'[t] == Cos[t], x[0] == 1, y[0] == 0}; sol2[tf_?NumericQ] := NDSolve[eqns, {x, y}, {t, 0, tf}][[1]] p = tf /. FindRoot[(x[tf] /. sol2[tf]) == 1, {tf, 5}] // Quiet 6.28319 p = RootApproximant[p/Pi] Pi 2*Pi sol = NDSolve[eqns, {x, y}, {t, 0, p}]; Plot[Evaluate[x[t] /. sol], {t, 0, p}] ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, p}] Bob Hanlon On Mon, Dec 12, 2011 at 6:42 AM, Sam Takoy <sam.takoy at yahoo.com> wrote: > Hi, > > Suppose I'm solving a system of ODE's for x[t] and y[t] and I know > that there is a periodic solution, but beyond that I know nothing, not > even how long the period is. So I want to stop NDSolve when x repeats > a certain value. Here's an example: > > sol = NDSolve[{x'[t] == -Sin[t], y'[t] == Cos[t], x[0] == 1, y[0] == > 0}, {x, y}, {t, 0, 6}]; > ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, 6}] > > This solution goes from 0 to 6, but I want it to go from 0 until x(t) > = 1 again. > > What's the best way to accomplish this? > > Many thanks in advance, > > Sam
- References:
- Terminate NDSolve by a condition
- From: Sam Takoy <sam.takoy@yahoo.com>
- Terminate NDSolve by a condition