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

7 次查看(过去 30 天)
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!

采纳的回答

Walter Roberson
Walter Roberson 2021-12-6
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 个评论
Simone Montozzi
Simone Montozzi 2021-12-6
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by