Hand Written function in Constraint function

Hi guys!
I would ask you a question. I’m trying to define an h constraint on matlab script, however here I have the necessity to insert an hand - written sign function (applied to a casadi SX) of the form:

function val = SGN(x)
if x>=0
    val=1;
else
    val=-1;
end
end

I have already tried to save it in the same working folder as .m file but when i launch the compilation the system returns this error:

Conversion to logical from casadi.SX is not possible.

So the question is: It is possible to do what I eplain before or maybe I’m making a mistake ?
thank you in advance
Giulio

Hi,

what you try to implement here is a non differentiable function.
Which is not compatible with the automatic differentiation tool CasADi.
Maybe using a smooth version of that function makes sense for you

Cheers!