How can I use fminunc with a function that has a vector as output?
Show older comments
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!
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!