用CVXOPT求解二次规划问题,老是出错
import numpy as np
from cvxopt import solvers,matrix
G=matrix(np.identity(10),tc='d')
print('G\n',G,np.shape(G))
# lim=np.array([1000,1000])
# h=matrix(np.kron(np.ones((1,5)),lim),tc='d')
h=matrix([1000.,1000.,1000.,1000.,1000.,1000.,1000.,1000.,1000.,1000.])
print('h\n',h,np.shape(h))
N=5
p=2
n=2
k_steps = 100
X_K = np.zeros((n, k_steps))
X_K[:, 1] = [20., -20.]
print('X_K\n',X_K,np.shape(X_K))
U_K = np.zeros((n, k_steps))
P=matrix(np.arange(100).reshape(10,10),tc='d')
print('P\n',P,np.shape(P))
E=matrix(np.random.randint(2,500,(10,2)),tc='d')
print(E)
print(X_K[:,1])
q=matrix(np.dot(E,(X_K[:,1].reshape(2,1))),tc='d')
print('q\n',q,np.shape(q))
print(type(q))
U_k = solvers.qp(P, q, G, h)
Traceback (most recent call last):
File "C:\Users\shinelon\Desktop\python\lession_work\venv\lib\site-packages\cvxopt\misc.py", line 1429, in factor
lapack.potrf(F['S'])
ArithmeticError: 2
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\shinelon\Desktop\python\lession_work\venv\lib\site-packages\cvxopt\coneprog.py", line 2065, in coneqp
try: f = kktsolver(W)
File "C:\Users\shinelon\Desktop\python\lession_work\venv\lib\site-packages\cvxopt\coneprog.py", line 1981, in kktsolver
return factor(W, P)
File "C:\Users\shinelon\Desktop\python\lession_work\venv\lib\site-packages\cvxopt\misc.py", line 1444, in factor
lapack.potrf(F['S'])
ArithmeticError: 2
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\shinelon\Desktop\python\pythonProject--math\try2-math.py", line 65, in
U_k = solvers.qp(P, q, G, h)
File "C:\Users\shinelon\Desktop\python\lession_work\venv\lib\site-packages\cvxopt\coneprog.py", line 4485, in qp
return coneqp(P, q, G, h, None, A, b, initvals, kktsolver = kktsolver, options = options)
File "C:\Users\shinelon\Desktop\python\lession_work\venv\lib\site-packages\cvxopt\coneprog.py", line 2067, in coneqp
raise ValueError("Rank(A) < p or Rank([P; A; G]) < n")
ValueError: Rank(A) < p or Rank([P; A; G]) < n
h矩阵我改过为10*1的,还是一样错
能不能求出结果,不报错
我也遇到了