I am trying to call fminunc in a script file on a function defined in another file. The problem is that I want to give parameters to this function (e.g. 'y' and 'dt'), although it is a function of x.
So I have in my myfunc.m something like this:
function [f df] = myfunc(y,dt)f = @(x) (x - y)^2 / (2 * dt);if nargout>1 df = @(x) ((x - y) / dt);endend
Then in my other script file, I have something like this:
dt = 0.1;options = optimset('GradObj','on');for i = 1:n y = randn; result = fminunc(myfunc(y,dt), 0, options);end
The function 'res' is a function of x, but I want to be able to give it values that change as the for-loop is iterated through, and I am not quite sure how to do that. Any help would be appreciated.
Best Answer