SIMULINK: Using FMINSEARCH online for xpctarget

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.

Respuestas (3)

Guy Rouleau
Guy Rouleau el 17 de Oct. de 2011

0 votos

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 comentario

Yanbo
Yanbo el 15 de Ag. de 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

Iniciar sesión para comentar.

Guy Rouleau
Guy Rouleau el 17 de Oct. de 2011

0 votos

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 comentario

Gulzar Baig
Gulzar Baig el 10 de Jun. de 2017
Editada: Gulzar Baig el 10 de Jun. de 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....

Iniciar sesión para comentar.

Jakub
Jakub el 30 de Jun. de 2014

0 votos

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 comentarios

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
Jakub el 30 de Jun. de 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 el 30 de Jun. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Coder en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Oct. de 2011

Editada:

el 10 de Jun. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by