# The function fmincon does not report the right solution

Hello,
I am struggling to find two policy parameters that minimize the welfare losses. I first tried to set manually a loop over the parameter values. This method does work, but in order to consider all the possible values to the order 10^-2, the algorithm takes a LOT of time (because of indeterminate cases since I am solving the model under perfect foresight), and I don’t have much time since I have a deadline for the project (to have an idea, it’s been running for 2 days). When I decrease the number of possible combinations between the two parameters (a jump of 0.05 for example instead of 0.01), the result is not satisfying, the welfare loss is still greater than zero.
Hence, I tried the fmincon function. First, the function gives me different solutions when I change the starting point. Second, when it runs, I see that it can compute lower values of the welfare loss, but it doesn’t report the corresponding parameter values.

The loop over the 2 parameters : findopt.m (1.5 KB)

The command used for fmincon:
lb = [0,0];
ub = [1,1];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [0.5,0.5];
[xx,fval] = fmincon(@find_opt,x0,A,b,Aeq,beq,lb,ub)

the m-file used here:find_opt.m (119 Bytes)

The model : det6.mod (8.7 KB)

Hi,

First, it is perfectly normal that the `fmincon` function does not report the same solution when you change the starting point. This is so because this algorithm searches for a local minimum, and depending on the starting point, you may end up in a different local minimum (the only way to guarantee that this will never happen is if the function you’re minimizing is globally convex).

Concerning the second question: I’ve tried to run your code, and `fmincon` actually reports the parameter values that (supposedly) minimize your objective. They’re stored in the first return argument of `fmincon`, in this case inside `xx`. Or am I misunderstanding your problem?

Best,

Hi,