SIMULINK: Using FMINSEARCH online for xpctarget

6 views (last 30 days)
Shane
Shane on 17 Oct 2011
Edited: Gulzar Baig on 10 Jun 2017
Hey everyone I am having some issues. So I have this problem where I am using simulink to design an adaptive controller. I essentially take a set of data over a set of say 1 second and identify the main frequencies. With those identified frequencies I calculate my controller. I am trying to essentially minimize the coefficients of my controller to get enough gain to do the job but not to much that it will increase noise.
I insert a user-defined function and basically pass it the frequencies and try to fun "fminsearch" inside the block. The actual cost funciton is also a user defined function. Now I know the the command I am using will work when I do it in matlab and pass it the frequencies it will give me the correct coefficients out.
Is fminsearch and fmincon not useable in simulink? I just need a way to minimize a cost function "online" in simulink.

Answers (3)

Guy Rouleau
Guy Rouleau on 17 Oct 2011
In simulation, you can call fminsearch or fmincon from MATLAB S-function of from the MATLAB function as extrinsic.
You cannot generate code from fminsearch or fmincon. Only the functions listed here can generate and be used on xPC Target:
  1 Comment
Yanbo
Yanbo on 15 Aug 2013
Hey, Guy,
The link is not valid now.
If I want to use xPC target to perform somet optimization calculations in real time, given that fmincon and fminsearch are not applicable in xPC, what else can I resort to?
Cheers,
Yanbo

Sign in to comment.


Guy Rouleau
Guy Rouleau on 17 Oct 2011
In simulation, you can call fminsearch or fmincon from MATLAB S-function of from the MATLAB function as extrinsic.
You cannot generate code from fminsearch or fmincon. Only the functions listed here can generate and be used on xPC Target:
  1 Comment
Gulzar Baig
Gulzar Baig on 10 Jun 2017
Edited: Gulzar Baig on 10 Jun 2017
Dear Guy, My Simulink model is an 'objective function' itself. There are two parameters that I wish to optimize to curve fit the data using fminsearch (block).
So what I mean is that I put fminsearch block and connect the LSE to its input while the two parameters from its output are connected to the Simulink model. The simulation runs until parameters are found (Hint: Root finding in Algebriac Constaint). OR how to call fminsearch from S-function??? Any help....

Sign in to comment.


Jakub
Jakub on 30 Jun 2014
Hi Guy,
In recent Matlab editions the nubmer of functions supported by code generation changed. According to
the list includes fminsearch. However the usage scenario of fminsearch and other optimization functions is that we are usually using anonymous/nested functions in order to pass parameters to the function being optimized. Both approaches are unsupported by code generation. Therefore what is a preferred way of passing additional, user-defined parameters to functions like fminsearch?
Cheers, Jakub
  3 Comments
Jakub
Jakub on 30 Jun 2014
Thank you Ryan for the answer and the link. I must say that I am not a fan of persistent variables and globals, but it is the most reasonable solution for now.
Cheers, Jakub
Ryan Livingston
Ryan Livingston on 30 Jun 2014
I definitely share your sentiments about the need to use persistents here. But as you say, I believe this to be the most reasonable solution at present.

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!