CasADi labs is an open-ended platform for sharing knowledge about CasADi. Any user can guest-post by making pull-requests to the blogging repo.

##### CasADi-driven MPC in Simulink (part 2)
In this post, we have a new take on nonlinear MPC in Simulink using CasADi. Interpreter mode In an earlier post on MPC in Simulink, we used an interpreted 'Matlab system' block in the simulink diagram. This is flexible, but slow because of interpreter overhead. code-generation mode In an earlier post on S-Functions, we showed how Casadi-generated C code can be embedded efficiently in a Simulink diagram using S-functions. The result is fast, but has restrictions: only SqpMethod combined with Qrqp or Osqp solver can be code-generated (as of 3.
##### CasADi codegen and S-Functions
While the user guide does explain code-generation in full detail, it is handy to have a demonstration in a real environment like Matlab's S-functions. The problem We will design a Simulink block that implements a nonlinear mapping from ($\mathbf{R}^2$, $\mathbf{R}$) to ($\mathbf{R}$,$\mathbf{R}^2$): import casadi.* x = MX.sym('x',2); y = MX.sym('y'); w = dot(x,y*x); z = sin(x)+y+w; f = Function('f',{x,y},{w,z}); Code-generating You may generate code from this with: f.generate('f.c') However, we'll use the more advanced syntax since we have advanced requirements.
##### On the importance of NLP scaling

During my master's thesis at KULeuven on optimal control, one of the take-aways were that it's important to scale your variables. It helps convergence if the variables are in the order of 0.01 to 100.

##### Optimal control problems in a nutshell

Optimization. There's a mathematical term that sounds familiar to the general public. Everyone can imagine engineers working hard to make your car run 1% more fuel-efficient, or to slightly increase profit margins for a chemical company.

##### Easy NLP modeling in CasADi with Opti

Release 3.3.0 of CasADi introduced a compact syntax for NLP modeling, using a set of helper classes, collectively known as 'Opti stack'.

In this post, we briefly demonstrates this functionality.

##### CasADi-driven MPC in Simulink (part 1)

CasADi is not a monolithic tool. We can easily couple it to other software to have more fun. Today we'll be exploring a simple coupling with Simulink. We'll be showing off nonlinear MPC (NMPC).