MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Terminate NDSolve by a condition

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123640] Re: Terminate NDSolve by a condition
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Wed, 14 Dec 2011 06:00:12 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201112121142.GAA12764@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

But Sam...

Why doesn't EventLocator stop at the initial value, the FIRST time y[t] ==  
0?

Bobby

On Tue, 13 Dec 2011 04:41:13 -0600, Sam Takoy <sam.takoy at yahoo.com> wrote:

> Thank you.
>
>
> ________________________________
>  From: Oliver Ruebenkoenig <ruebenko at wolfram.com>
> To: Sam Takoy <sam.takoy at yahoo.com>
> Cc: mathgroup at smc.vnet.net
> Sent: Monday, December 12, 2011 6:46 AM
> Subject: [mg123614] 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


-- 
DrMajorBob at yahoo.com



  • Prev by Date: Minor problems with Mathematica 8 : private copy of stylesheet and
  • Next by Date: Re: color-bar legend for the LisContourPlot
  • Previous by thread: Re: Terminate NDSolve by a condition
  • Next by thread: How to run ".nb" file always in dos command line