MATLAB: Fmincon function help answer does not converge

fminconMATLAB

We have a group project that need to price series caps using two different method: a theoretical one and a practical one.
We want to set parameters to minimize the square errors.
In the main script, we have set an initial set of parameters.
But when we run the code, since the function we need to minimize is non linear and we are not able to calculate a gradient, the parameter just does not converge.
The result looks like follows:
Warning: To use the default trust-region-reflective algorithm you must supply
the gradient in the objective function and set the GradObj option to 'on'.
FMINCON will use the active-set algorithm instead. For information on
applicable algorithms, see Choosing the Algorithm in the documentation.
> In fmincon at 492
In main at 36
Solver stopped prematurely.
fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunEvals = 300 (the default value).
x =
NaN
NaN
NaN
our main code is this:
r_guess=0.003;
sigma_guess=0.02;
k_guess=0.3215;
x0=[r_guess;sigma_guess;k_guess];
%options.MaxIter = 1000;
%options.MaxFunEvals = 1000000000000;
[x]=fmincon(@HW_Cap_Optimizer,x0,[ ] ,[ ] ,[ ],[ ],[0;0;0])
%%%%%%%%%%%%%%%%%%%%%%%%%%%done
HW_Cap_Optimizer function calls a bunch of other functions which are non linear.
Really need help from you guys, thank you!

Best Answer

1) Is your objective function sum of squares? if it is then LSQNONLIN will be a better suited solver.
2) I see that you are setting MaxFunEvals to be a large number, but I don't see it being passed to FMINCON. Take a look at the doc of fmincon you have to pass the options as follows:
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
3) If none of those work for you, you may have to share your code with us to look through further. But please make sure you try the above and other different options as well. This is an excellent doc page that talks about what to do When the solver fails