Info

この質問は閉じられています。 編集または回答するには再度開いてください。

how to obtain the number of cases of length. but those matrices sum must be 30 or something value(on constraints)

1 回表示 (過去 30 日間)
Brian Kim
Brian Kim 2017 年 9 月 13 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
first, -constraints-
elements must be between 4 and 12
for example,
A=[6 7 8 9], sumA=sum(A)=30;
What is number of cases of length that can be obtained so that the sum becomes 30?
For reference,
If the length of the matrix is 5, A is [5 5 6 7 7].
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 13 日
Stephen, you should not close duplicate questions that have Answers unless the Answers also appear in the original location.

回答 (2 件)

KSSV
KSSV 2017 年 9 月 13 日
x0 = 4 ; x1 = 12 ;
x = x0:x1 ;
iwant = cell([],1) ;
count = 0 ;
for i = 1:length(x)
A = nchoosek(x,i) ;
thesum = sum(A,2) ;
if any(thesum==30)
count = count+1 ;
iwant{count} = A(thesum==30,:) ;
end
end
You have the possible combinations whose sum is 30 in iwant.
  3 件のコメント
KSSV
KSSV 2017 年 9 月 13 日
You need to only provide x.....no changes required.....
Brian Kim
Brian Kim 2017 年 9 月 13 日
ah~ i am sorry. i mean, some of elements can be same.

Walter Roberson
Walter Roberson 2017 年 9 月 13 日
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 9 月 13 日
If you just need to calculate the number of different ways that you can partition a number with particular (possibly repeated) integers, then see the mathematics outlined at https://math.stackexchange.com/questions/15521/making-change-for-a-dollar-and-other-number-partitioning-problems

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!