Most of the code structure is taken from: https://github.com/MMehrez/MPC-and-MHE-implementation-in-MATLAB-using-Casadi If you want to understand more about MPC and MHE using CasADi in MATLAB then visit: https://www.youtube.com/playlist?list=PLK8squHT_Uzej3UCUHjtOtm5X7pMFSgAL