Re: Seeing a solution of a differential equation as it run, using EvaluationMonitor
- To: mathgroup at smc.vnet.net
- Subject: [mg118904] Re: Seeing a solution of a differential equation as it run, using EvaluationMonitor
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Sun, 15 May 2011 07:04:27 -0400 (EDT)
This eliminates the "empty" Module:
Initialization :> (process[t_, y_] := (AppendTo[pt, {t, y}];
Pause[0.01]))
Bobby
On Sat, 14 May 2011 02:09:39 -0500, Nasser M. Abbasi <nma at 12000.org> wrote:
> On 5/13/2011 7:30 PM, Nasser M. Abbasi wrote:
>> Here is a small example of looking at solution of some basic made
>> up ode as it runs:
>>
>> --------------------
>> x1 = 0; x2 = 0;
>> pt = {{x1, x2}};
>>
>> Dynamic[ListPlot[pt, Joined -> False, PlotRange -> {{0, 2*Pi}, {0,
>> 7}}]]
>>
>> (*when pt is updated below, this causes ListPlot to revaluate
>> automatically*)
>> process[t_, y_] := Module[{},
>> {pt = Append[pt, {t, y}]};
>> Pause[0.05] ]
>>
>> (*solve the ode, use EvaluationMonitor*)
>> eq = y''[t] == Cos[t];
>> sol = NDSolve[{eq, y[0] == 1, Derivative[1][y][0] == 1}, y[t],
>> {t, 0, 2*Pi}, EvaluationMonitor :> process[t, y[t]]]
>>
>
> I thought I update the above example to show how to do
> it inside Manipulate.
>
> A Manipulate slider is used to enter maximum simulation time,
> and then the display on the Manipulate output will show
> the solution, but one step at time (as opposed to normal
> way of showing the final solution in one shot.)
>
> --------------------------------------
> Manipulate[
> (
> pt = {{0, 0}};
>
> NDSolve[{y''[t] == Cos[t], y[0] == 1, y'[0] == 1}, y[t], {t, 0, maxt},
> EvaluationMonitor :>process[t,y[t]]];
>
> Dynamic[ListPlot[pt, Joined -> False ,PlotRange -> {{0, maxt}, {0,
> 7}}]]
> ),
>
> {{maxt,0.5,"max time"},0.5,10,.1},
>
> TrackedSymbols->{maxt},
> SynchronousUpdating->False, (*important to have this*)
> ContinuousAction->False, (*and this also*)
> Initialization:>
> (
> process[t_,y_]:=Module[{},pt=Append[pt, {t, y}]; Pause[0.01]]
> )
> ]
> ------------------------------------
>
> That is all. I think it is a little more interesting to
> be able to see the solution as it progress. The Pause[0.01]
> is needed to be able to do this. One can adjust this as
> needed (may be make a Manipulate parameter also).
>
> Isn't Mathematica fun?
>
> --Nasser
>
--
DrMajorBob at yahoo.com