67 views (last 30 days)

Show older comments

I want to create a 4x4 matrix of integers such that:-

Say, M=[ A B C D ; E F G H ; I J K L ; M N O P ]

A+B+C+D>=value from user

A+B+C+D<=value from user

A+E+I+M>=value from user

A+E+I+M<=value from user

and likewise for all columns and rows.

Rik
on 23 Feb 2021

What have you tried?

Also, don't forget that this might not be possible for some values provided by the user.

Matt J
on 23 Feb 2021

You can try to formulate it as an integer program.

M=optimvar('M',[4,4],'type','integer');

Constraints.columns=sum(M,1)<=colvalues;

Constraints.rows=sum(M,2)<=rowvalues;

prob=optimproblem('Objective', 0,'Constraints',Constraints );

sol=solve(prob)

Matt J
on 24 Feb 2021

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!