Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i try to use InvariantErrorPlot command for a generic system of ODE but i find only example with pre-building equations from Mathematica Packages. This is one of them:

system = GetNDSolveProblem["PerturbedKepler"]
vars = system["DependentVariables"]
H = system["Invariants"]
time = {T, 0, 290};
step = 1/25;
Met = {"SymplecticPartitionedRungeKutta", "DifferenceOrder" -> 10, 
   "PositionVariables" -> {Subscript[Y, 1][T], Subscript[Y, 2][T]}};
sol = NDSolve[system, time, Method -> Met, StartingStepSize -> step, 
   MaxSteps -> Infinity];
 Evaluate[{Subscript[Y, 1][T], Subscript[Y, 2][T]} /. sol], 
InvariantErrorPlot[H, vars, T, sol, PlotStyle -> {Blue, Red}] 

Now the question is simple: can I modify it to use InvariantErrorPlot for my equations? And if so, how?

Thanks a lot.

share|improve this question
up vote 3 down vote accepted

Just spelunking a little I got this for the harmonic oscillator problem:

eqs = {y[1]'[T] == y[2][T], y[2]'[T] == -y[1][T]};
iniconds = {y[1][0] == 1, y[2][0] == 0};
invariants = {1/2 (y[1][T]^2 + y[2][T]^2)};
vars = {y[1][T], y[2][T]};
system = {eqs, iniconds, vars, {T, 0, 10}, {}, invariants, {}};
erksol = NDSolve[NDSolveProblem@system, Method -> "ExplicitRungeKutta"];
InvariantErrorPlot[invariants, vars, T, erksol]

Mathematica graphics

The two empty lists on the system definition requires some more work to find out what they are.

share|improve this answer
thanks a lot, this is a very good starting point for me ! – Panichi Pattumeros PapaCastoro Mar 12 '14 at 0:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.