Asked by Martijn
on 21 May 2012

Dear all,

I have a .mex64 function that was build from C++ libraries (IPOPT solver) and is able to solve an optimzation problem (NLP constraint).

I can call this function from an .m file easily, but how should I do it in Simulink? An S-function will build a mex file, but I already have this MEX file.

The final goal is to run the optimization in real-time (Model Predictive Control) on a XPC target machine.

*No products are associated with this question.*

Answer by Titus Edelhofer
on 21 May 2012

Hi Martijn,

for the xPC Target you will need to have the source code of IPOPT solver available. You can write your S-function and for compilation add all source files for IPOPT. Should work, but I guess your solver code (and therefore the resulting S-function) will be fairly large ...

Titus

Titus Edelhofer
on 21 May 2012

You just add the sources to your call to mex:

mex mysfunction.c ipopt1.c ipopt2.c ipopt3.c

Titus

Kaustubha Govind
on 22 May 2012

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 1 Comment

## Martijn (view profile)

Direct link to this comment:http://nl.mathworks.com/matlabcentral/answers/38962#comment_80600

Using a simple mex file function I get the following error:

"Only MATLAB files are supported for code generation. Unsupported file extension 'mexw64' [...]"