Solve underdetermined system of equations in matlab

╄→尐↘猪︶ㄣ 提交于 2019-12-02 00:12:55

What you have is often called integer-linear programming and it is known to be NP-hard (which means don't hold your breath until a solution comes out).

If you want to solve it without the integerness, you have a linear program and hence can use linprog. If you think of your unknown matrix as vector of unknown entries then column sum is just

col_sum = kron(eye(4),[1,1,1]);

col_sum =

     1     1     1     0     0     0     0     0     0     0     0     0
     0     0     0     1     1     1     0     0     0     0     0     0
     0     0     0     0     0     0     1     1     1     0     0     0
     0     0     0     0     0     0     0     0     0     1     1     1

Similarly, row sum is

row_sum = repmat(eye(3),1,4);

row_sum =

     1     0     0     1     0     0     1     0     0     1     0     0
     0     1     0     0     1     0     0     1     0     0     1     0
     0     0     1     0     0     1     0     0     1     0     0     1

These are your equality constraints also you have the inequality constraints but only to bound the unknown values. linprog can bound them as extra arguments. However you don't have an objective function which you can make up something like sum of all unknowns minimized or one of them or any other linear objective would do or you can leave it empty and you get any feasible result.

Aeq = [col_sum;row_sum]
beq = [2 6 6 1 5 7 3]';

X = linprog([],[],[],Aeq,beq,zeros(12,1),10*ones(12,1))% 0 <= vars <= 10

X = reshape(X,3,4)

X =

    0.6550    2.0160    2.0160    0.3130
    1.1192    2.5982    2.5982    0.6845
    0.2258    1.3859    1.3859    0.0025


>> sum(X,1)

ans =

    2.0000    6.0000    6.0000    1.0000

>> sum(X,2)

ans =

    5.0000
    7.0000
    3.0000

If you have certain entries that are guaranteed to be zero etc. Then it might be possible that all solutions are forced to be integers. Otherwise you need to have nonconvex specific integer programming solvers for example given here

The 'fmincon' optimisation approach might be able to help you out - it allows for nonlinear inequality constraints to be added before running: http://uk.mathworks.com/help/optim/ug/nonlinear-inequality-constraints.html

EDIT: Just spotted the use of row sums to help determine the optimised answer, so the answer I gave might be of limited use. Would still be worth a shot though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!