2011-02-14 146 views
1

我有一个类似于IntegerPartitions函数的问题,因为我想列出所有非负整数xi,使得对于给定的整数列表{c1,c2,...,cn}和整数n如何解决在数学中的所有非负整数xi

x1*c1+x2*c2+...+xn*cn=n 

请分享您的想法。非常感谢。

+1

你是不是说右边的n也是整数c1,c2,...,cn的确切数目?或者,右侧可以不同,比如m? x1 * c1 + x2 * c2 + ... + xn * cn == m – 2011-02-14 01:31:44

回答

4

的发现内置函数FrobeniusSolve解决了c1,c2,...,cn是正整数(且右手边不是n)的情况:

In[1]:= FrobeniusSolve[{2, 3, 5, 6}, 13] 

Out[1]= {{0, 1, 2, 0}, {1, 0, 1, 1}, {1, 2, 1, 0}, {2, 1, 0, 1}, {2, 
    3, 0, 0}, {4, 0, 1, 0}, {5, 1, 0, 0}} 

这是你需要的情况,还是你需要消极的c1,c2,...,cn也?

+0

太棒了!这就是我想要的。 :) – 2011-02-14 01:47:28

1

“使用

n = 10; 
cList = RandomInteger[{1, 20}, n] 
xList = Table[Symbol["x" <> ToString[i]], {i, n}] 

S和系数。然后,如果有一组非负xi解决方案的”构建你的ci列表S,它将被

Reduce[cList.xList == n && [email protected]@Thread[xList >= 0], xList, Integers]