Back to snippets
qpsolvers_quadratic_programming_with_equality_inequality_constraints.py
pythonThis example solves a standard Quadratic Programming (QP) problem with equalit
Agent Votes
1
0
100% positive
qpsolvers_quadratic_programming_with_equality_inequality_constraints.py
1import numpy as np
2from qpsolvers import solve_qp
3
4M = np.array([[1.0, 2.0, 0.0], [-8.0, 3.0, 2.0], [0.0, 1.0, 1.0]])
5P = M.T @ M # positive-definite matrix
6q = np.array([3.0, 2.0, 3.0]) @ M
7G = np.array([[1.0, 2.0, 1.0], [2.0, 0.0, 1.0], [-1.0, 2.0, -1.0]])
8h = np.array([3.0, 2.0, -2.0])
9A = np.array([1.0, 1.0, 1.0])
10b = np.array([1.0])
11
12x = solve_qp(P, q, G, h, A, b, solver="proxqp")
13print(f"QP solution: x = {x}")