Say I have a function
[f,g,h] = function (x)
In the file function.m
in Matlab. How can I find the value x
, eg using fminunc
, which maximizes g
? The fminunc
documentation only handles the case when the objective function returns a single value.
You must provide fminunc
with a function that returns a scalar, so in your case you'll just have to declare a helper function that returns g
:
g = function helper_func(x)
[f, g, h] = func(x);
and feed the helper function into fminunc
:
x = fminunc(@helper_func, x0);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.