I got the same problem as in question:
DSolve
, NDSolve
with WhenEvent
Give Incorrect Solution for Simple ODE.
The boundary conditions are not fulfilled in the solution using the WhenEvent
.
Can this problem be solved somehow?
Clear["Global`*"]
z = 0.1;
T = 4*2*π;
m = 4;
sol = DSolveValue[{x''[t] == -1/(4*m^2)* x[t] - 2*z/m*x'[t] +
1/m^2*Cos[t], x[0] == x[T], x'[0] == x'[T],
WhenEvent[x[t] == 0, x'[t] -> -x'[t]]},
x[t], {t, 0, T},
Method -> {"Shooting",
"StartingInitialConditions" -> {x[0] == 2, x'[0] == -0.60}}];
Plot[sol, {t, 0, T}]