Optimization cost function file

Is it possible that optimization can be done without creating a seperate function file for the cost function and the constraint?..if yes then how can we do it....?

5 comentarios

Rik
Rik el 8 de Jun. de 2018
What function are you using? Most functions will allow you to have a function handle as an input, so you can include a handle to a function in that same m-file (or even use an anonymous function).
Aquatris
Aquatris el 8 de Jun. de 2018
Check the document page of "fmincon" where they have examples for this. Most solvers for Matlab follow similar input format.
Mondeep maz
Mondeep maz el 9 de Jun. de 2018
It is an objective function consisting a sum of variables...problem is that i want to design the optimization such that no of variables of the objective function at each iteration can get changed...if i use a function handle i wont b able to change it i suppose...so i want a way to get around this problem
sabreen farouq
sabreen farouq el 19 de Ag. de 2022
where i can find this famous cost function ?
Walter Roberson
Walter Roberson el 20 de Ag. de 2022
There are a few example cost functions such as rosenbeck, but mostly you write your own cost function depending on what you want to optimize.
See also Problem Based Optimization

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 9 de Jun. de 2018

1 voto

Each iteration of the objective function called by fmincon or ga or similar must involve the same number of variables, and must be deterministic (no random values.)
You can use different numbers of variables for different calls to the minimizer, including in a loop. That could involve creating a new anonymous function for each iteration of the loop.
An objective function which is just the sum of variables can be expressed as just @sum; for a weighted sum, @(x) sum(x.*weights) or more robustly @(x) sum(x(:).*weights(:)) to be sure you do not have row/column difficulties.

Más respuestas (0)

Categorías

Preguntada:

el 8 de Jun. de 2018

Comentada:

el 20 de Ag. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by