Skip to content

FAQ: Error messages that you get when you use MX() instead of MX.sym()

András Retzler edited this page Oct 31, 2022 · 1 revision

If you forget .sym, that can cause troubles, because in MATLAB, this will return a zero matrix:

>> casadi.MX(3,3)

ans = 

zeros(3x3,0nz)

...while this will correctly return a symbol that is a 3x3 matrix:

>> casadi.MX.sym('a',3,3)

ans =

a

This happens if the decision variables declared incorrectly propagate down to nlpsol:

Error using casadi.nlpsol (line 988)
.../casadi/core/function_internal.cpp:145: Error calling IpoptInterface::init for 'solver':
.../casadi/core/nlpsol.cpp:398: Assertion "sparsity_out_.at(NLPSOL_X).is_dense() &&
sparsity_out_.at(NLPSOL_X).is_vector()" failed:
Expected a dense vector 'x', but got 30x1,0nz.

Error in my_master_script (line 111)
            solver_casadi = casadi.nlpsol('solver','ipopt', nlp, opt_casadi);

The solution is to use MX.sym('a',3,3) instead of MX(3,3).

Clone this wiki locally