MATLAB: For loop for gradient nested within objective function of fmincon

fminconfor loopgradient

Best Answer

It looks to me as if your gradient should have 10 elements.

Did you declare all those variables global in the workspace? Maybe n isn't being passed. For more reliable ways to include extra parameters and avoid global variables, see Passing Extra Parameters.

Alan Weiss

MATLAB mathematical toolbox documentation