# Why WhenEvent doesn't work in this case?

yb[a_?NumericQ] := a^2;
eqns = {x'[s] == -yb[s], WhenEvent[x'[s] > 0, {yb[s] -> - yb[s]}],
x'[0] == 0}
NDSolve[eqns, x[s], {s, -50, 50}]


The WhenEvent doesn't evaluate x'[s] correctly,is there anyway to make this work?

• Is this an example or a real problem? – Alex Trounev Jan 3 at 20:06
• this is example,but actually I need to evaluate the sign of first derivative when solving first-order partial differential equation... – Xminer Jan 3 at 20:10
• The problem is incorrect, so you need to change the question. Add a real example. – Alex Trounev Jan 3 at 20:24

eqns = {x'[s] == - sgn[s] yb[s], sgn[0] == +1,WhenEvent[x'[s] > 0, {sgn[s] -> -sgn[s] }], x'[0] == 0}

• yb[s] is an extern function , WhenEvent can only change state variables of NDSolve. – Ulrich Neumann Jan 3 at 20:43