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

12 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Dez. 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 Kommentare
Simone Montozzi
Simone Montozzi am 6 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by