I test race_cars in the acados_python example,“f_expl = vertcat(
sdota,
v * sin(alpha + C1 * delta),
v * C2 * delta - kapparef_s(s) * sdota,
Fxd / m * cos(C1 * delta),
derD,
derDelta,
)”,i change the v to casadi.sqrt(v),the solution failed.And it happened in my own example,I’m guessing this happens in every case,not just in my model. And when I tested it with print_level turned on, I noticed that the BAbt matrix appears nan when I use sqrt (a declared MX variable), and if I replace sqrt with power (a declared MX variable,0.5) it also appears, whereas power(,2.3) doesn’t, and anytime it’s 0 to 1, it’s nan
Hi~ I encounter the same problem as well. According to OCP solver fails after adding nonlinear constraint - #2 by FreyJo, if you initialize v as 0, sqrt() can not be linearized at 0. So, to solve the problem, just initializing v as a small positive number, such as 0.001.
Hi all,
this is expected behaviour as the derivative of the square root function tends to infinity as you approach zero. Initializing at a positive value might not be sufficient. You need reformulate your model such that the square root function will never be evaluated at zero, e.g. the expression \sqrt{x^2 + \epsilon} with \epsilon > 0 works fine as the term inside the square root will always be positive independent of the value of x.
Best, Katrin