create matrix of integers with specified sum in column and row

1 visualización (últimos 30 días)
Zaid Ali Basharat
Zaid Ali Basharat el 23 de Feb. de 2021
Editada: Matt J el 24 de Feb. de 2021
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.
  1 comentario
Rik
Rik el 23 de Feb. de 2021
What have you tried?
Also, don't forget that this might not be possible for some values provided by the user.

Iniciar sesión para comentar.

Respuestas (1)

Matt J
Matt J el 23 de Feb. de 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)
  16 comentarios
Zaid Ali Basharat
Zaid Ali Basharat el 24 de Feb. de 2021
Ok now I got what I wanted but is there anyway we can do it without exapnding the upper column values?
Matt J
Matt J el 24 de Feb. de 2021
Editada: Matt J el 24 de Feb. de 2021
The solver will tell you if it is possible for the given set of input ranges. If it returns. sol.M=[], then it is not possible.

Iniciar sesión para comentar.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by