How to use linprog in Simulink?

11 次查看(过去 30 天)
Avinash Siravuru
Avinash Siravuru 2013-10-23
评论: Zack Peters 2013-10-25
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.

回答(1 个)

Zack Peters
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 个评论
Avinash Siravuru
Avinash Siravuru 2013-10-25
Hi Zack, I tried code.extrinsic too. Whenever the code reaches the execution point of 'linprog' , it gives me a dimension mismatch error between the rows of A and the length of b vector. I rechecked it many a time to ensure the dimensions match. I also created a couple of test cases with the right dimensions. However, the error still persists.
Moving on, I want to give you a brief summary of what I intend to do. Using the optimization I hope to get a few optimal torque values for my robot which I will have to apply on the robot in ADAMS and study its behavior. Initially I did not want to optimize online, ie., at every time-step. So I wrote a code in Matlab itself and for a predefined trajectory, I got optimal values. I then tried to interpolate the data using splines. Now the data structure that Matlab uses for splines couldn't be directly brought into Simulink. So I let it stay in the Workspace and I was accessing it from there. Now, I still got into these code generation error issue every time I executed the 'ppval' function. I added it to code.extrinsic function and I then started getting some other error which I couldn't understand. I gave up on the offline approach and I then wrote the whole code again directly in Simulink(online approach) wishing that the problem would get resolved. But, I am still stuck as I mentioned above. Could you help me find a way around this? Thanks.
-Avinash
Zack Peters
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by