fminsearch for existing simulation

Hey guys,
I have recently created an aerodynamic trajectory model. The goal is to optimize for two Values for which i have an equation that should be mnimal. Now i want to use fminsearch (or something else if it fits better) to run over my whole simulation and calculate the value of the equation. To optimize it, there are plenty of other input values in the equation, that should be considered and changed by fminsearch. How can i do that without putting my whole simluation in one formula?
I dont use additional toolboxes, nor Simulink.
Thanks!

1 comentario

Walter Roberson
Walter Roberson el 14 de Sept. de 2020
You can pass the handle of a true function to fminsearch . You are not required to pass the handle to an anonymous function.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 14 de Sept. de 2020

0 votos

As Walter said, fminsearch does not know or care how many lines of code are used to implement your objective function. Bear in mind, though, that fminsearch is not built for problems with many variables. With more than about 6 unknowns, it typically performs poorly.

3 comentarios

Good to know thanks!
I also got a tip with fminsearchbnd which is perfect because you can easily define boundaries. It now works perfectly fine. The only thing i dont like is that i have to change the original simulation by passing the Init-values so it doesnt work without being called by optimizer anymore. Would be nicer to have it in a seperate m-file.
function optimizer
%initial values
Init = [4.5 0.5 0.16];
LB = [ 3 0 0];
UB = [ 10 3 0.5];
options = optimset('PlotFcns',@optimplotfval);
Init_opt = fminsearchbnd(@mysimulation, Init, LB, UB, options);
function [value, thing1, thing2] = mysimulation(Init)
tPhase1 = Init(1); % Would be nice to have the value 4.5 here
value = thing1/(thing2/100);
Matt J
Matt J el 14 de Sept. de 2020
Editada: Matt J el 14 de Sept. de 2020
I also got a tip with fminsearchbnd which is perfect because you can easily define boundaries
Since you appear to have only a single unknown variable, the stock Matlab function fminbnd would work as well.
The only thing i dont like is that i have to change the original simulation by passing the Init-values so it doesnt work without being called by optimizer anymore.
No, that's quite unnecessary. Your objective function can call other functions, so there is no reason why the simulation code cannot reside in its own mfile. The only thing fminsearch/fminbnd/fminsearchbnd cares about is that it has access to some function which takes a guess for the unknown as input and spits an objective function value back as output. It doesn't know or care what code is used to obtain that output value, or how that code is structured.
Walter Roberson
Walter Roberson el 14 de Sept. de 2020
"To optimize it, there are plenty of other input values in the equation, that should be considered and changed by fminsearch"
To me that suggests that the number of variables to be optimized over is more than 1.

Iniciar sesión para comentar.

Categorías

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

Productos

Etiquetas

Preguntada:

el 14 de Sept. de 2020

Comentada:

el 14 de Sept. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by