Running the following code:
k = optimvar('k',2);c = optimvar('c',2);objec = (k-2)'*(k-2)+(c-1)'*(c-1);prob = optimproblem('Objective',objec);problem = prob2struct(prob);[x,fval] = quadprog(problem);sol.c = x(1:2);sol.k = x(3:4);% Matlab documention claims:
% [x,fval] = quadprog(___), for any input variables, also returns fval, the value of the objective function at x:
% fval = 0.5*x'*H*x + f'*x
fval .5*x'*problem.H*x+problem.f'*x % the real objective function value at x is
evaluate(objec,sol) x'*problem.H*x+problem.f'*x % it seems the 0.5 multiplication is incorrect and this is a bug
yields the folloing output:
fval =
-10
ans =
-10
ans =
0
ans =
0
Is this a known bug with quadprog in Matlab 2020a?
Best Answer