Azzera filtri
Azzera filtri

Obtaining n^th order polynomial combinations in an array

2 visualizzazioni (ultimi 30 giorni)
Hi, I want to obtain an array consisting of all the possible combinations of polynomials upto n^(th) order. For example, for order 2, the array would look like
[1, x(1), x(2), x(3), x(4), x(5), x(6), x(1)*x(1), x(1)*x(2), x(1)*x(3), x(1)*x(4), x(1)*x(5), x(1)*x(6), x(2)*x(2), x(2)*x(3), x(2)*x(4), x(2)*x(5), x(2)*x(6), x(3)*x(3), x(3)*x(4), x(3)*x(5), x(3)*x(6), x(4)*x(4), x(4)*x(5), x(4)*x(6), x(5)*x(5),x(5)*x(6), x(6)*x(6)]
Whereas for order 3, it will look like
[1, x(1), x(2), x(3), x(4), x(5), x(6), x(1)*x(1), x(1)*x(2), x(1)*x(3), x(1)*x(4), x(1)*x(5),
x(1)*x(6), x(2)*x(2), x(2)*x(3), x(2)*x(4), x(2)*x(5), x(2)*x(6), x(3)*x(3), x(3)*x(4),
x(3)*x(5), x(3)*x(6), x(4)*x(4), x(4)*x(5), x(4)*x(6), x(5)*x(5),x(5)*x(6),
x(6)*x(6), x(1)*x(1)*x(1), x(1)*x(1)*x(2), x(1)*x(1)*x(3), x(1)*x(1)*x(4),
x(1)*x(1)*x(5), x(1)*x(1)*x(6), x(1)*x(2)*x(2), x(1)*x(2)*x(3), x(1)*x(2)*x(4),
x(1)*x(2)*x(5), x(1)*x(2)*x(6), x(1)*x(3)*x(3), x(1)*x(3)*x(4), x(1)*x(3)*x(5),
x(1)*x(3)*x(6), x(1)*x(4)*x(4), x(1)*x(4)*x(5), x(1)*x(4)*x(6), x(1)*x(5)*x(5),
x(1)*x(5)*x(6), x(1)*x(6)*x(6), x(2)*x(2)*x(2), x(2)*x(2)*x(3), x(2)*x(2)*x(4),
x(2)*x(2)*x(5), x(2)*x(2)*x(6),x(2)*x(3)*x(3), x(2)*x(3)*x(4), x(2)*x(3)*x(5), x(2)*x(3)*x(6),
x(2)*x(4)*x(4), x(2)*x(4)*x(5), x(2)*x(4)*x(6), x(2)*x(5)*x(5), x(2)*x(5)*x(6), x(2)*x(6)*x(6),
x(3)*x(3)*x(3),x(3)*x(3)*x(4), x(3)*x(3)*x(5), x(3)*x(3)*x(6), x(3)*x(4)*x(4), x(3)*x(4)*x(5),
x(3)*x(4)*x(6), x(3)*x(5)*x(5), x(3)*x(5)*x(6), x(3)*x(6)*x(6), x(4)*x(4)*x(4), x(4)*x(4)*x(5),
x(4)*x(4)*x(6), x(4)*x(5)*x(5),x(4)*x(5)*x(6), x(4)*x(6)*x(6), x(5)*x(5)*x(5), x(5)*x(5)*x(6),
x(5)*x(6)*x(6), x(6)*x(6)*x(6)]
So far, I am manually defining such arrays, but as you can see, it is very tedious. Is there a way to code this for any random order n? Thank you for all the help!

Risposte (1)

KSSV
KSSV il 20 Dic 2022
Modificato: KSSV il 20 Dic 2022
REad about nchoosek
You may also refer to the below file exchange: https://in.mathworks.com/matlabcentral/fileexchange/9029-nmultichoosek

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by