StepMonitor problem

• To: mathgroup at smc.vnet.net
• Subject: [mg127433] StepMonitor problem
• From: Daniel <dosadchy at its.jnj.com>
• Date: Wed, 25 Jul 2012 02:29:55 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: mathgroup-newout@smc.vnet.net
• Delivered-to: mathgroup-newsend@smc.vnet.net

```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]

```

• Prev by Date: Re: Integration of expressions with symbolic limits
• Next by Date: Re: Can anyone see a faster way to compute quantities for a pair or large matrices?
• Previous by thread: Re: Using Fit to interpolate data