Optimization using fmincon for a simulink model

11 次查看(过去 30 天)
Hi, I have a simple simulink model using embedded matlab function. The model is supplied with a signal (T) which is a 100 by 1 column array, and another input variable (N) which is a constant value. The model produces two outputs (P &D) which are of the same size as T. The equation for the model is D=T/(P*N)
By providing the values of different N (one value for one simulation), D can be changed. Now I want to minimize D, for a range of values of N between 1 and 250. I have specified my objective function as function [D]=myobjectivefcn(x) D=T./(P.*x) end
I am running the optimtool to select the solver and specify the upper and lower bound for x as 1 and 250, with sart value as 1. But its not working. Can somebody please help me, I dont know how to connect my simulink model with the optimization. Really really appreciate any help in correcting the code.
Thanks
  2 个评论
Khalid
Khalid 2014-11-25
I have a very similar question, as does another poster from this thread:
Is moving over to Matlab really the best option? Matlab is great in terms of how flexible it is; but I find I am better at re-using parts of code/model and finding my mistakes when using Simulink.
Besides, this must be possible, as optimisation from within a Simulink model is completed in the built-in MPC controller block (as well as in other places I'm sure). Out of curiosity I had a quick look at how they do this, and there is a MATLAB Function block, and within that block they make a call to "mpcblock_optimizer_mex", which is set as extrinsic using
coder.extrinsic('mpcblock_optimizer_mex');
But unfortunately as it's a mex function I can't see any more than that. Any thoughts anyone? As I've noted in the other post I tried declaring fmincon as an extrinsic function but its then not possible to pass function handles to it.
Any pointers much appreciated.
- Khalid.
Yousif Al-sagheer
Yousif Al-sagheer 2015-4-23
编辑:Yousif Al-sagheer 2015-4-23
Hi, MPC block in simulink is designed for linear system. In linear system predictive control the control low finds the optimal values using a control law equation which consists of some matrix multiplication (the control law can be found in literature, "Model based predictive control: A practical approach J. A. Rossiter P.62"). So I do not think MPC block in simulink contains any fmincon command inside it.

请先登录,再进行评论。

回答(1 个)

Babak
Babak 2012-11-29
My suggestion, move everything in MATLAB script language (m-files) if possible and don't do an optimization in Simulink. You can write your own time steps like simulink in script.
If you cannot move everything to script lamguage: I would write an m-file and put a for loop, looping on different values for N (or x) and inside the for loop call your simulation to run, with sim() command. you can get the result out of your simulink model in different ways, like you could use a "to workspace" or "to file" block. Before, the end of the for loop, you need to save the output result of simulink, somehow, like in a local matrix in the main calling script file.

类别

Help CenterFile Exchange 中查找有关 Manual Performance Optimization 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by