Using 'while' loop for MX/SX type

368 views
Skip to first unread message

Paulina Quintanilla

unread,
Aug 31, 2021, 5:13:36 AM8/31/21
to CasADi
Hi all,

I am implementing MPC using CasADi. My model has an algebraic loop in one of the equations, so I was trying to implement a fixed-point iteration using a 'while' loop to solve the algebraic loop. 

However, the while loop has one variable which is a MX type, so I get the error: 
Conversion to logical from casadi.MX is not possible.

Does anyone know how to implement a while loop for MX/SX variables? 
or - may be even better - does anyone know how to solve an algebraic loop using another method (not the fixed-point iteration)? 

Thank you!

Paulina.

joaosa...@gmail.com

unread,
Aug 31, 2021, 2:49:33 PM8/31/21
to CasADi
numeric_variable = full(evalf(mx_variable));

Joel Andersson

unread,
Aug 31, 2021, 3:05:57 PM8/31/21
to CasADi
Hi,
Normally you would handle an algebraic loop by a algebraic variable, i.e. use a DAE formulation of the dynamics.
That works with both a "shooting" approach and a fully simultaneous approach ("collocation").

Joel
Reply all
Reply to author
Forward
0 new messages