Dear all,

I am trying to solve a quadratic minimization problem with quadprog, but I obtain results that are very different from fmincon. I do not understand why. My problem is the following:

where || || is the Euclidean norm. I have written the following code (with quantities similar to my problem):

`% Setup values (just as example)`

n = 4;AA = [12, -1, 0, 0; ... 0, 0, 111, -1];bb = [0; 0];x = [1; 10; 1; 61];% options for fmincon

optionsFmincon = optimset('LargeScale', 'off', ... 'Algorithm', 'interior-point', ... 'UseParallel', 'never', ... 'MaxFunEvals', 20000, ... 'GradObj', 'on', ... 'TolX', 1e-9, ... 'TolFun', 1e-9, ... 'TolCon', 1e-9, ... 'MaxIter', 10000, ... 'Display', 'none' ... );% options for quadprog

optionsQuadprog = optimset('Algorithm', 'interior-point-convex', ... 'TolX', 1e-12, ... 'TolFun', 1e-12, ... 'TolCon', 1e-12, ... 'MaxIter', 10000, ... 'Display', 'none' ... );% Fmincon minimization

lowerBound = -1000000000000000*ones(params.n, 1); %fictitious lower and upper bounds

upperBound = +1000000000000000*ones(params.n, 1);[out1, Jopt1, exitflag1, output1] = fmincon(@(y) cost(x, y, n), x, [], [], [], [], lowerBound, upperBound, @(y) constraints(y, AA, bb), optionsFmincon);% Solution with quadprog

H = eye(n);f = -2*eye(n)*x;A = [];b = [];Aeq = AA;beq = bb;lb = [];ub = [];x0 = [];[out, Jopt, exitflag, output] = quadprog(H, f, A, b, Aeq, beq, lb, ub, x0, optionsQuadprog);% Comparison of results

[out1, out][out1'*H*out1-2*x'*eye(n)*out1+x'*eye(n)*x, out'*H*out-2*x'*eye(n)*out+x'*eye(n)*x][norm(x-out1)^2, norm(x-out)^2][norm(AA*out1-bb), norm(AA*out-bb)]% cost function for fmincon

function [J, gradient] = cost(x, y, n)J = (x-y)'*eye(n)*(x-y); % equivalent to J = y'*eye(n)*y - (2*eye(n)*x)'*y; since I can omit x*eye(n)*x

gradient = -2*(x-y);end% constraints function for fmincon

function [c, ceq] = constraints(x, AA, bb)ceq = AA*x-bb;c = [];end

If you execute the code, you get very different solutions. The optimal cost of the fmincon is equal to 0.23048, while the optimal cost of quadprog is 3823 (therefore, also the values of the optimal y are very different). In both cases the constraints are satisfied.

Probably I am making something wrong, but I do not understand what.

Any help from you is really appreciated. Thank you in advance

## Best Answer