SIMULINK: Using FMINSEARCH online for xpctarget
Afficher commentaires plus anciens
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.
Réponses (3)
Guy Rouleau
le 17 Oct 2011
0 votes
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 commentaire
Yanbo
le 15 Août 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
Guy Rouleau
le 17 Oct 2011
0 votes
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 commentaire
Gulzar Baig
le 10 Juin 2017
Modifié(e) : Gulzar Baig
le 10 Juin 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....
Jakub
le 30 Juin 2014
0 votes
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 commentaires
Ryan Livingston
le 30 Juin 2014
Typically, asking for new information is best served in a new question.
One workaround is to use persistent variables to maintain the parameters. The idea is to call your function:
foo(x, param1, param2)
before invoking fminsearch to "set" the values of param1 and param2 in place of constructing an anonymous function. Then, those parameters can be used inside of foo when the solver invokes your function.
See:
for an idea on how to do this.
Jakub
le 30 Juin 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
le 30 Juin 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.
Catégories
En savoir plus sur Simulink Design Optimization dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!