Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7171
| From | Sam Takoy <sam.takoy@yahoo.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Terminate NDSolve by a condition |
| Date | 2011-12-13 10:47 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jc7af4$osu$1@smc.vnet.net> (permalink) |
| References | <201112121142.GAA12764@smc.vnet.net> <alpine.LRH.2.00.1112120545180.24437@wopr.wolfram.com> |
Thank you.
________________________________
From: Oliver Ruebenkoenig <ruebenko@wolfram.com>
To: Sam Takoy <sam.takoy@yahoo.com>
Cc: mathgroup@smc.vnet.net
Sent: Monday, December 12, 2011 6:46 AM
Subject: Re: Terminate NDSolve by a condition
On Mon, 12 Dec 2011, Sam Takoy 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
>
>
Sam, how about
tend = 100;
sol = NDSolve[{x'[t] == -Sin[t], y'[t] == Cos[t], x[0] == 1,
y[0] == 0}, {x, y}, {t, 0, tend},
Method -> {"EventLocator", "Event" -> y[t],
"Direction" -> 1,
"EventAction" :> {Throw[tend = t, "StopIntegration"]}}]
tend
Plot[Evaluate[{y[t], y'[t]} /. sol], {t, 0, tend}]
Plot[Evaluate[{x[t], x'[t]} /. sol], {t, 0, tend}]
ParametricPlot[Evaluate[{x[t], y[t]} /. sol], {t, 0, tend}]
Documentation: tutorial/NDSolveEventLocator
Hope this helps,
Oliver
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Terminate NDSolve by a condition Sam Takoy <sam.takoy@yahoo.com> - 2011-12-13 10:47 +0000
csiph-web