Advertisement
makispaiktis

Python - Quadratic Programming

Oct 30th, 2022 (edited)
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. from cvxopt import solvers, matrix
  2.  
  3. P = matrix([[4.0, 1.0], [1.0, 2.0]])
  4. q = matrix([1.0, 1.0])
  5. print(P)
  6. print(q)
  7.  
  8. G = matrix([[-1.0, 0.0], [0.0, -1.0]])
  9. h = matrix([0.0, 0.0])
  10. A = matrix([[1.0], [1.0]])
  11. b = matrix([1.0])
  12. print(G)
  13. print(h)
  14. print(A)
  15. print(b)
  16.  
  17. sol = solvers.qp(P, q, G, h, A, b)
  18. optimal = sol['x']
  19. print("Optimal")
  20. print(optimal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement