Tobias
Tobias

Reputation: 514

How can I return more than one output from function called by fmincon?

I want to minimize a function via fmincon:

[param, fval]=fmincon(@(param) functionfile(param, additional inputs), ...);

However, in addition to the parameters and the function value at the minimum, I would like to get some other stuff back from the function that fmincon calls.

I do not want to use global variables. Is there any other way I can do that?

Upvotes: 1

Views: 1146

Answers (1)

Jan
Jan

Reputation: 5172

A problem will be that fmincon calls your function over and over again in an iterative procedure. So you should specify, when you want your stuff returned, in particular, if it changes with params

If the stuff you want to get in return is a fixed value - you should require it before or afterwards in an extra function call.

If your stuff is just fixed numbers, you can include them in the output of the function such that they will appear in fval. However, doing so you will have a drop in performance.

Upvotes: 0

Related Questions