python上的二次编程问题
我在MATLAB上有一个代码,在该代码中,我使用函数四元素来求解二次优化:
deltaU = quadprog(H,f,M,gamma)
这是MPC的一部分,其中H是30x30矩阵,FA 30x1矩阵,M A A 180x30矩阵和Gamma A 180x1矩阵。 在MATLAB上,它可以正常运行,并且代码返回Resul Vector(30x1),
但是,当我尝试将此代码传输到Python时,我无法使它起作用,
我正在使用qpsolvers使用Quadprog求解器
import numpy as np
import qpsolvers
from qpsolvers import solve_qp
....
sol_qp = solve_qp(H, f, M, gamma)
: 这是一个非类型对象。 nonepe object的图像 我已经用求解器网页的示例测试了求解器,并且可以使用。 我认为矩阵尺寸存在一些问题,但是它们与我在MATLAB中使用的尺寸完全相同。 您现在该如何工作?
对不起,我的英语,我还在学习 谢谢!
编辑:我将完整的代码添加到完整的矩阵定义,
我不能在此处放置它,因为字符的限制, 这是矩阵的定义: https://www.toptal.com/www.teptal.com/deevelicers/developers/hastebin/hastebin/xunopeyivi.yamaml
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现错误,求解器不接受像矩阵(30,1)这样的一个维矩阵,它们需要是一个数组(30,)
也许不是最好的方法,但是我通过这样做解决了它:
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: