Advertisement
makispaiktis

Optimization - Quadratic - quadprog, CVX

Oct 31st, 2022 (edited)
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.73 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% Quadprog for: min ((2x_1^2 + x_2^2 + x_1x_2) + (x_1 + x_2))
  6. display('***********************************');
  7. display('quadprog');
  8. H = [4 1; 1 2];
  9. f = [1 1]';
  10. A = [-1 0; 0 -1];
  11. b = [0 0]';
  12. Aeq = [1 1];
  13. beq = 1;
  14. [x_optimal, f_min] = quadprog(H, f, A, b, Aeq, beq)
  15. display('***********************************');
  16. display(' ');
  17.  
  18.  
  19. %% CVX for: min ((2x_1^2 + x_2^2 + x_1x_2) + (x_1 + x_2))
  20. display('***********************************');
  21. display('CVX');
  22. cvx_begin quiet
  23.     variable x(2);
  24.     minimize(0.5 * x'*H*x + f'*x);
  25.     subject to
  26.         A*x <= b;
  27.         Aeq*x == beq;
  28. cvx_end
  29. disp("cvx_optval = " + num2str(cvx_optval));
  30. display('***********************************');
  31. display(' ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement