How to assign elements in matrix after satisfying certain constraint?

1 回表示 (過去 30 日間)
SYED ABOU ILTAF HUSSAIN
SYED ABOU ILTAF HUSSAIN 2018 年 9 月 6 日
コメント済み: dpb 2018 年 9 月 7 日
How to create a m*n matrix such that the sum of the first (m-1) elements must be less than or equal to the mth element and also the sum of the first (n-1) elements must be less than or equal to the nth element?
For example:
A = [a11, a12, a13, a14; a21, a22, a23, a24; a31, a32, a33, a34]
such that:
a11+a12+a13<=a14
a21+a22+a23<=a24
a31+a32+a33<=a34
a11+a21<=a31
a12+a22<=a32
a13+a23<=a33
a14+a24<=a34
Code for creating matrix A.
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 9 月 7 日
I would read the constraints as
all( all( cumsum(A(:,1:end-1),2) <= A(:,2:end), 2 ), 1 )
all( all( cumsum(A(1:end-1,:),1) <= A(2:end, :), 1), 2 )
dpb
dpb 2018 年 9 月 7 日
May be, but the internal constraint wasn't what was written...maybe showing alternative interpretations gives OP some of the feedback needed...

サインインしてコメントする。

回答 (1 件)

SYED ABOU ILTAF HUSSAIN
SYED ABOU ILTAF HUSSAIN 2018 年 9 月 7 日
Thank you everyone for your help

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by