Re: Modification of Variable in NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg108078] Re: Modification of Variable in NDSolve
- From: "Christoph Lhotka" <christoph.lhotka at univie.ac.at>
- Date: Mon, 8 Mar 2010 06:10:40 -0500 (EST)
- References: <hmiikh$3r6$1@smc.vnet.net> <hmlese$jmc$1@smc.vnet.net>
Hello,
I would use the low level functions, NDSolve`ProcessEquations,
NDSolve`Iterate and
"NDSolve`Reinitialize"
to modify the variables in NDSolve (it is ment for exactly that purpose,
to reset the initial conditions to a new value).
unfortunatly the event location method seems not to work with this
approach. so one has to write his own code to detect the event (by looking
at state@"SolutionVector" for example.
Look up the Advance documentation in NDSolve on this topic. For sure you
will find a solution, which is fast and reliable.
Christoph
On So, 7.03.2010, 11:10, DrMajorBob wrote:
> I'm not sure why you're dividing into intervals (explained in a previous
> post??), but here's a code that loops:
>
> Clear[findCrossing]
> findCrossing[{low_, high_, a1Low_, b1Low_, f1Low_}] :=
> Module[{t1, aa, bb, ff, at, bt, ft},
> {t1, {aa, bb, ff}, {at, bt, ft}} =
> Block[{a, b, f, sol, crossings, cross},
> {{sol}, {crossings}} =
> Reap[NDSolve[{a'[t] == dA, b'[t] == dB, f'[t] == dF,
> a[low] == a1Low, b[low] == b1Low, f[low] == f1Low}, {a, b,
> f}, {t, low, high},
> Method -> {"EventLocator", "Event" -> f[t] - 5,
> "Direction" -> 1, "EventAction" :> Sow[t]}]];
> {a, b, f} = {a, b, f} /. sol;
> {cross = First@crossings, {a, b, f}, {a@cross, b@cross, f@c