I want to process a CasADi expression to detect linear and nonlinear parts, using structural zero detection
"is_zero".
For SX variables, this works fine. I do something like in the following short example:
import casadi.*
x1 = SX.sym('x1');
x2 = SX.sym('x2');
x = vertcat(x1, x2);
x0 = rand(size(x));
f = [x1 + x2; 0 ];
% generate and eval f
f_fun = Function('f_fun', {x},{f});
f_new = SX(f)
f_new(1) = f_new(1) - 1 * x1
f_new(1) = f_new(1) - x2
f1 = f_new(1);
f1 = f1.simplify()
f1.is_zero()
This works fine and gives the final output "1"
Sadly for MX expressions this does not work.
import casadi.*
x1 = MX.sym('x1');
x2 = MX.sym('x2');
x = vertcat(x1, x2);
x0 = rand(size(x));
f = [x1 + x2; 0 ];
% generate and eval f
f_fun = Function('f_fun', {x},{f});
f_new = MX(f)
f_new(1) = f_new(1) - 1 * x1
f_new(1) = f_new(1) - x2
f1 = f_new(1);
f1 = f1.simplify()
f1.is_zero()
here the last output is "0".
Am I missing something when using MX here?
Please let me know if this is ready to be tested!
Best regards,
Jonathan