Optimization using fmincon for a simulink model
8 views (last 30 days)
Show older comments
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 Comments
Khalid
on 25 Nov 2014
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
on 23 Apr 2015
Edited: Yousif Al-sagheer
on 23 Apr 2015
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.
Answers (1)
Babak
on 29 Nov 2012
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.
0 Comments
See Also
Categories
Find more on Manual Performance Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!