MATLAB Answers

create matrix of integers with specified sum in column and row

67 ビュー (過去 30 日間)
Zaid Ali Basharat
Zaid Ali Basharat 2021 年 2 月 23 日
編集済み: Matt J 2021 年 2 月 24 日
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 件のコメント
Rik 2021 年 2 月 23 日
What have you tried?
Also, don't forget that this might not be possible for some values provided by the user.


回答 (1 件)

Matt J
Matt J 2021 年 2 月 23 日
You can try to formulate it as an integer program.
prob=optimproblem('Objective', 0,'Constraints',Constraints );
  16 件のコメント
Matt J
Matt J 2021 年 2 月 24 日
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.





Community Treasure Hunt

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

Start Hunting!

Translated by