Hi,
I have the following function "fun()" which uses fminunc to find a solution for an optimization problem. I want to use the function "fx()" to store the history of the values of the objective function after each iteration. (for simplicity the example just increments the value of the variable res) The code produces the error:
error: handles to nested functions are not yet supported
error: evaluating argument list element number 4
error: called from:
error: /tmp/fun.m at line 9, column 17
Here is the code:
function res = fun()
X = rand(5, 5);
y = rand(5, 1);
t = rand(5, 1);
res = 12;
options = optimset("MaxIter", 100, "OutputFcn", @fx);
fminunc(@(t)(fm(X, y, t)), t, options)
function stop = fx(t, optimvalues, state)
res = res + 1
stop = false;
end
end
function [J] = fm(X, y, theta)
c = X * theta - y;
J = c' * c / (2 * length(y));
end
Is there a workaround for this?
Thanks in advance.