How to use linprog in Simulink?
19 次查看(过去 30 天)
显示 更早的评论
I am running a co-simulation using Adams and Simulink. As a part of this procedure, I need to optimize a few variables. I used the 'Matlab Function Box' to write the requisite code. However it is not compiling. I get the following error. 'The function 'linprog' is not supported for standalone code generation. ' I got the same error using both linprog and fmincon.
Please help me resolve this. My work is stuck because of this problem. Thank you.
0 个评论
回答(1 个)
Zack Peters
2013-10-24
Hi Avinash,
Currently, both LINPROG and FMINCON are not supported for code generation. What is going on is that all of the code within your "MATLAB Function" block is being converted into a C S-function to create a more efficient simulation. To call functions that are not supported for code generation you can use the coder.extrinsic property to declare your function. Alternatively you can use the "Interpreted MATLAB Function" block which makes a call to the MATLAB engine and does not perform any sort of basic code generation. In either situation the result of a lack of code generation is a potentially slower simulation performance.
Additionally, both of the blocks listed above are going to be called at every time-step. This means that LINPROG or FMINCON could be run every time-step of your model. Is this what you really intend to do?
Here is a list of functions supported for code generation and information on the coder.extrinsic command.
~Zack
2 个评论
Zack Peters
2013-10-25
Hi Avinash,
I believe that you were on the right track with creating the trajectory offline. How important is the interpolation between two data points? The From File and From Workspace blocks will perform a linear interpolation on data.
If the interpolation is that important then I would either revisit the error you were getting with PPVAL (which as you noticed is not supported for code generation as of R2013b) or implement your own spline interpolation algorithm within handwritten MATLAB code.
~Zack
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!