access a variable from the last iteration of optimization function: fmincon
Afficher commentaires plus anciens
I am using "fmincon" to optimize an objective function. MATLAB does iteration until one of the exit criteria happens. What I need is to use the value of a variables in my "objective function" code from the last step in current step. Actually, I wanna know if one variable in current step is equal to its value of the previous steps. I am grateful for any help.
Réponses (1)
Walter Roberson
le 3 Avr 2011
0 votes
You could use "global" or "persistent" but note that fmincon doesn't promise to evaluate in any particular order.
2 commentaires
Ibehma01
le 3 Avr 2011
Walter Roberson
le 3 Avr 2011
You need to assign the new value to the global variable before leaving the evaluation function.
You can detect that you are on the first iteration of the function because the global variable will have the empty array for its value. Unless, of course, you ran the function before in the same session without clearing the global variable...
Catégories
En savoir plus sur Choose a Solver 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!