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.


1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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