How can I use fminunc with a function that has a vector as output?

7 visualizaciones (últimos 30 días)
Hi everyone! This is my first question in the forum. I am a novice with Matlab.
I created a function (myfun) that has as input a vector (x) of 3 elements and some parameters (a, b, c). This function has as output a vector of 3 elements, each of which I want to minimize.
I found this method to pass extra parameters, that involves the use of the function 'fminunc'.
x0 = [100, 100, 100];
f = @(x) myfun(x, a, b, c);
[x, fval] = fminunc(f, x0);
It would be perfect if the output of my funcion were a single value, but I have a vector as output, and I have this error:
Error using fminunc (line 383)
Supplied objective function must return a scalar value.
My question is: how I can use an optimization function (like fminunc) with a function that has as output a vector and not a single value?
Many thanks in advance!

Respuesta aceptada

Walter Roberson
Walter Roberson el 6 de Dic. de 2021
You cannot do that. You have a multi objective optimization and need to use gamultiobj or similar.
You have fundamental questions about what you should do if lowering the value of one output requires increasing the value of another one. Which output is most important to minimize?
You can easily construct incompatible objectives, such as asking to minimize the vector [x, -x].
  2 comentarios
Simone Montozzi
Simone Montozzi el 6 de Dic. de 2021
Hi Walter, thank you.
The outputs are 3 errors between the target values and the calculated values. So I would like all three to tend to zero.
I'm going to study gamultiobj.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by