Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Real time progress of NDSolve

  • To: mathgroup at smc.vnet.net
  • Subject: [mg129659] Real time progress of NDSolve
  • From: psycho_dad <s.nesseris at gmail.com>
  • Date: Sun, 3 Feb 2013 02:47:03 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-newout@smc.vnet.net
  • Delivered-to: mathgroup-newsend@smc.vnet.net

Hi all,
Lately I'd been trying to solve some very complicated ODEs (they arise from modifications of General Relativity), but there were two problems:
1) NDSolve would take several (15+) minutes to solve them,
2) Many times it would actually fail as the system is very stiff.
Trying to understand what was going on and also having a real time estimate of the progress of NDSolve, I came up with the following code that actually helped me address the issues mentioned above:

data = {{0, 1}};
k = 0;
ProgressIndicator[Dynamic[k], {0, 30}]
Dynamic[ListPlot[data, Frame -> True,
  PlotRange -> {{0, 31}, {0, 1.2}}]]
NDSolve[{y'[x] == y[x] Cos[x + y[x]], y[0] == 1}, y, {x, 0, 30},
  StepMonitor :> (Pause[.02]; Set[k, x]; AppendTo[data, {x, y[x]}])];

The ProgressIndicator provides the real time estimate of the progress and the Dynamic+ListPlot show where NDSolve has a certain "difficulty" (notice the "hiccup" in this example at x~12). The ODE used is of course very simple and not the one I used in practice.

In any case, this is not groundbreaking or anything, but it helped me and I thing it's quite cool, so I decided to share it.

Cheers



  • Prev by Date: Re: Mathematica and Lisp
  • Next by Date: Re: Mathematica and Lisp
  • Previous by thread: Re: making a Module or Column that will print lines interspersed with plots
  • Next by thread: Re: Real time progress of NDSolve