I am solving an DAE problem with NDSolve. It is a physical problem related to friction forces: one mass on the X axis and another on the Y axis, linked by a bar (L=5). There is a part of the equation that must change the sign (the one related to a[t]), and I try to control it by a[t]. I am able to solve this problem as it is a piecewise problem, but I would like to solve it as a whole, so I have tried to use WhenEvent and DiscreteVariables.
deqns= {
x''[t] == -(1/5) T[t] x[t] + 0.1 a[t] (9.8 + 1/5 T[t] (3 + y[t])),
y''[t] == (49 - 2/5 T[t] (3 + y[t]))/5, x[t]^2 + (3 + y[t])^2 == 25,
WhenEvent[x'[t] == 0, a[t] -> -a[t]],
x[0] == 4, y[0] == 0, a[0] == 1,
x'[0] == 0, y'[0] == 0};
sol = NDSolve[
deqns, {x, y, T, a}, {t, 0, 10},
DiscreteVariables -> a,
Method -> {"IndexReduction" -> Automatic}
];
Physical constraints force -4 <= x[t] <= 4, and 0 <= y[t] <=2. My question is about the solution obtained for a[t]. It is defined as "DiscreteVariables", and a[t] should change between -1 and +1 but when I plot it, it is not true. Any suggestion?
Art