Passing parameter from the objective function to the output function

Hi everyone, I would like to know how I can pass a parameter from the objective function to the output function in an optimization problem. Here is an example of what I would like to do:
options = optimset(@fminunc,'GradObj','on','Hessian','on','OutputFcn', @outfun);
[x fval] = fminunc(@rosenboth,[-1;2],options)
function [f g H extraparameter] = rosenthree(x)
% Calculate objective f, gradient g, Hessian H
f = 100*(x(2) - x(1)^2)^2 + (1-x(1))^2;
g = [-400*(x(2)-x(1)^2)*x(1)-2*(1-x(1));
200*(x(2)-x(1)^2)];
H = [1200*x(1)^2-400*x(2)+2, -400*x(1);
-400*x(1), 200];
extraparameter = x(1)^2 - x^(2)^3
end
function stop = outfun(x,optimValues,state, extraparameter)
stop = false;
switch state
case 'init'
hold on
case 'iter'
% Concatenate current point and objective function
% value with history. x must be a row vector.
history.fval = [history.fval; optimValues.fval];
history.x = [history.x; x];
history.extraparameter = [history.extraparameter; extraparameter]
plot(history.fval, history.extraparameter)
case 'done'
hold off
otherwise
end
end
Does anyone have an idea?? Thank you very much in advance.
Àlex

 採用された回答

Alan Weiss
Alan Weiss 2013 年 11 月 22 日

0 投票

You can use nested functions along the lines of passing information for this other purpose.
Alan Weiss
MATLAB mathematical toolbox documentation

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeManual Performance Optimization についてさらに検索

質問済み:

2013 年 11 月 22 日

回答済み:

2013 年 11 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by