Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #11061

StepMonitor problem

From Daniel <dosadchy@its.jnj.com>
Newsgroups comp.soft-sys.math.mathematica
Subject StepMonitor problem
Date 2012-07-25 06:30 +0000
Message-ID <juo3qb$14h$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


Hello,

I use NDSolve to solve a differential system of equations and I need to plot the solution during the execution of NDSolve. I use the StepMonitor option.

For a differential system it works great, at each step I get the time and the function values.

But - for an algebraic-differential system it doesn't work. Instead of function values I get the function derivative values! (took me some time to realize that). The EvaluationMonitor correctly gives the function values.

Do I use the StepMonitor correctly?

Example to illustrate the problem:

Solve an algebraic-differential system, while saving values with StepMonitor and EvaluationMonitor:

{sol, {dataStep, dataEv}} = Reap[
   NDSolve[{x'[t] == y[t]^2 + x[t] y[t], 2 x[t]^2 + y[t]^2 == 1, 
     x[0] == 0}, {x, y}, {t, 0, 10},
    StepMonitor :> Sow[{t, x[t], y[t]}, "stepMonitor"],
    EvaluationMonitor :> Sow[{t, x[t], y[t]}, "evaluationMonitor"]
    ],
   {"stepMonitor", "evaluationMonitor"}];

Plotting the solution and EvaluationMonitor shows correspondence:

Plot[{x[t], y[t]} /. sol // Evaluate, {t, 0, 10}, PlotRange -> All]
ListPlot[
  Transpose[{dataEv[[1, All, 1]], #}] & /@ 
   Transpose[dataEv[[1, All, 2 ;;]]], PlotRange -> All]

Plotting the StepMonitor shows discrepancy:

ListPlot[Transpose[{dataStep[[1, All, 1]], #}] & /@ 
  Transpose[dataStep[[1, All, 2 ;;]]], PlotRange -> All]

Plotting the solution derivatives shows correspondence to StepMonitor:

Plot[{x'[t], y'[t]} /. sol // Evaluate, {t, 0, 10}, PlotRange -> All]

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

StepMonitor problem Daniel <dosadchy@its.jnj.com> - 2012-07-25 06:30 +0000

csiph-web