[R] All nonnegative integer solution
Robin Hankin
r.hankin at noc.soton.ac.uk
Mon Nov 19 15:26:59 CET 2007
Hello Amin
The partitions library does this.
If N=4 and k=3:
> library(partitions)
> blockparts(rep(4,3),4)
[1,] 4 3 2 1 0 3 2 1 0 2 1 0 1 0 0
[2,] 0 1 2 3 4 0 1 2 3 0 1 2 0 1 0
[3,] 0 0 0 0 0 1 1 1 1 2 2 2 3 3 4
>
The solutions are enumerated in the columns.
HTH
rksh
On 19 Nov 2007, at 09:57, aminzoll at ece.tamu.edu wrote:
> Dear all,
> Is there any method in R to find all possible nonnegative integer
> solutions to the linear equation with unit coefficients as follow:
> X1+X2+...+Xk=N
> Thank you,
> Amin Zollanvari
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
More information about the R-help
mailing list