sparse marix and linprog
4 次查看(过去 30 天)
显示 更早的评论
Hi I want to solve linear programming model in MATLAB with linprog function. I need to create eye matrix in 994840x994840. I want to create it with sparse(eye(994840)), but I got "out of memory" error. Is it any way to solve my problem?
Thank you.
0 个评论
回答(1 个)
Matt J
2014-11-20
speye(994840)
5 个评论
John D'Errico
2014-11-20
ones(994840) will be a FULL matrix. There are no zeros at all. So use of a sparse form to store it will be less efficient. It will require more memory to store than a simple full matrix, since sparse is only efficient when the matrix is actually sparse.
Anyway, you don't want to create ones(994840), a matrix that would require
994840*994840*8 = 7917653004800
bytes to store, so roughly 8 terabytes of memory there!
Matt J
2014-11-20
编辑:Matt J
2014-11-20
fatema,
As John says, trying to explicitly create a matrix as large and memory-consuming as ones(994840) is too brute force. You need to look to more indirect ways. If you show us the problem in more detail, we might be able to give better advice.
As an example, if you're doing this because some subset of your inequality constraints looks like
[ones(N), S]*x<=b
where S is an NxM sparse or small matrix and N=994840, then you could introduce an additional unknown variable q and impose the equality constraint,
q=[ones(1,N), zeros(1,M)]*x
Now the inequality constraints can be replaced by
[ones(N,1), sparse(N,N), S]*[q;x]<=b
But notice that modified constraint matrix
A=[ones(N,1), sparse(N,N), S]
is now much more sparse and manageable.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Nonlinear Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!