I have a code on Matlab where I use the function quadprog to solve a quadratic optimization:
deltaU = quadprog(H,f,M,gamma)
This is part of an MPC where H is a 30x30 matrix, f a 30x1 matrix, M a 180x30 matrix and gamma a 180x1 matrix. On matlab it works ok and the code returns the resul vector (30x1)
However, when I try to transfer this code to Python, I can't make it work
I am using the quadprog solver from qpsolvers:
import numpy as np
import qpsolvers
from qpsolvers import solve_qp
....
sol_qp = solve_qp(H, f, M, gamma)
The result of this is a NoneType object. Image of the NoneType object I have tested the solver with the examples of the webpage of the solver and it works. I think that there is some problem with the matrix sizes, however they are exactly the same that the ones i used in matlab. Do you now how I can do it work?
Sorry for my english, I'm still learning Thanks!
Edit: I Add the complete code with the complete matrix definition
I can't put it here because of the limit of characters, here is the definition of the matrix: https://www.toptal.com/developers/hastebin/xunopeyivi.yaml
CodePudding user response:
I found the error, the solver do not accept the one dimensional matrix like matrix (30,1), they need to be an array (30,)
Maybe not the best way to do it, but I solved it by doing this:
f2 = f[:,0]
gamma2 = gamma[:,0]