Replacing one IC seems to work: ClearAll[f, F, inv, sol] f[w_?NumericQ] := Im[PolyLog[2, -E^(I*w)]] F[w_?NumericQ] := NIntegrate[f[t], {t, 0, w}] inv[w_?NumericQ, wp_?NumericQ]:= 0.5*wp^2+F[w] sol[l_, c_] := NDSolve[ {wp[x] == w'[x], wp'[x] == -f[w[x]], wp[ 0] == c, Mod[Abs[w[0] - w[l]], 2*Pi] == 0}, {w, wp}, {x, 0, l}, MaxStepFraction -> 0.01, MaxSteps -> Infinity, Method -> {"FixedStep", Method -> Automatic} ]; out = sol[5, 0.2] // First ; w[5] - w[0] /. out {wp[0], wp[5]} /. out F[w[5] /. out] - F[w[0] /. out] Table[inv[w[x], wp[x]] /. out, {x, 0, 5, 0.5}] I'd expect [projection][1] method to work here, but for some reason it throws an error: sol[l_, c_] := NDSolve[ {wp[x] == w'[x], wp'[x] == -f[w[x]], wp[ 0] == c, wp[l] == c}, {w, wp}, {x, 0, l}, MaxStepFraction -> 0.01, MaxSteps -> Infinity, Method -> {"FixedStep", Method -> {"Projection", Method -> Automatic, "Invariants" ->{inv[w[x], wp[x]] }}} ]; out = sol[5, 0.2] // First ; (* NDSolve::nnum1: The function value inv[w[0.],wp[0.]] is not a number when the arguments are {0.,{0.,0.}}. *) [1]: https://reference.wolfram.com/language/tutorial/NDSolveProjection.html