Multinomial matrix
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to generate a multinomial matrix such that with given K(interger)>0 I can get a matrix with all the possible combination of K+1 variables whose sum is from 1 to K eg for K=3, we have x1, x2, x3, x4 variables
we should have
1 0 0 0
...
0 0 0 1
2 0 0 0
...
0 0 0 2
1 1 0 0
...
3 0 0 0
...
1 1 0 1
There should be total 34 rows/combination it is impossible to manually input if k increases I wonder if anyone can suggest a proper way/function to generate such a matrix?
0 comentarios
Respuestas (1)
Bruno Luong
el 27 de Feb. de 2011
K=3
allVL1(K+1,K,'<=')
ans =
0 0 0 0
0 0 0 1
0 0 1 0
0 1 0 0
1 0 0 0
0 0 0 2
0 0 1 1
0 0 2 0
0 1 0 1
0 1 1 0
0 2 0 0
1 0 0 1
1 0 1 0
1 1 0 0
2 0 0 0
0 0 0 3
0 0 1 2
0 0 2 1
0 0 3 0
0 1 0 2
0 1 1 1
0 1 2 0
0 2 0 1
0 2 1 0
0 3 0 0
1 0 0 2
1 0 1 1
1 0 2 0
1 1 0 1
1 1 1 0
1 2 0 0
2 0 0 1
2 0 1 0
2 1 0 0
3 0 0 0
Discard the first row if you don't need all-zero vector.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!