Azzera filtri
Azzera filtri

How can I pass parameters from the objective function to the nonlcon function when using fmincon

1 visualizzazione (ultimi 30 giorni)
Hi,
I'm using fmincon in combination with a non-linear simulink model. As one simulation cycle takes a signifikant amount of time I would like to prevent that the simulink model is called twice: Once for the objective function f(x) and once for the non-linear constraint function c(x). During one simulation f(x) and c(x) are calculated, thus I would like to pass the relevant c(x) values during the objective function call to the nonlcon call to save the second simulation run.
Do I have to define a global variable to pass that kind of information or exists a more elegant way to solve that problem?
Kind regards, Oliver

Risposta accettata

Walter Roberson
Walter Roberson il 11 Apr 2016
The nonlinear constraint routine may be called multiple times before finding a point within bounds to be run through the objective function. However, the optimizer breaks up the problem into multiple sub-problems that it believes / hopes will not violate the nonlinear constraints. Therefore there is not a one-to-one relationship between f(x) and c(x) being called.
If you have an expensive function that must be called by both, then you may wish to implement that function with a "cache". See for example http://www.mathworks.com/matlabcentral/fileexchange/49949-cachedcall . A similar version that saves in memory could also be programmed.
  2 Commenti
walli
walli il 11 Apr 2016
Ah ok, I thought the objective function and non-linear constraint function would be called straight successively. However, I was wrong - Thanks for clarifying.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Manual Performance Optimization in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by