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개)

카테고리

질문:

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