Re: array ordered
- Subject: [mg3197] Re: array ordered
- From: pnardon at ulb.ac.be (Pasquale Nardone)
- Date: 18 Feb 1996 03:25:52 -0600
- Approved: usenet@wri.com
- Distribution: local
- Newsgroups: wri.mathgroup
- Organization: Université Libre de Bruxelles
- Sender: daemon at wri.com
I propose you to do the following code: first define a function f with the following defs: f[x_,f[y__]]:=f[x,y]; f[t___,x_,z___,x_,y___]:=0; f[t___,x_,z___,y_,u___]:=f[t,y,z,x,u]/;(x>y) f[0]:=0; then define the function which will give you all part: AllCombination[liste_]:= Module[{tmp,res}, tmp=Select[ Complement[ Flatten[ Outer[f,liste,liste]],{}],(Head[#]==f)&]; res=Join[Map[f,liste],tmp]; Do[ { tmp=Select[ Complement[ Flatten[Outer[f,liste,tmp]],{}],(Head[#]==f)&]; res=Join[res,tmp]},{Length[liste]-2}]; Return[res]] that's it: total=AllCombination[{1,2,3,4,5,6}] contains all combination: f[1],f[2],...,f[1,2,3,4,5,6]. now you introduce your data thick={0.48,0.71,1.41,3.45,5.61,13.49}; and an auxillary function: g[x_]:=thick[[x]]; g[x_,y__]:=thick[[x]]+g[y]; which applyed to total gives: thethickness=total/.{f->g} {0.48, 0.71, 1.41, 3.45, 5.61, 13.49, 1.19, 1.89, 3.93, 6.09, 13.97, 2.12, 4.16, 6.32, 14.2, 4.86, 7.02, 14.9, 9.06, 16.94, 19.1, 2.6, 4.64, 6.8, 14.68, 5.34, 7.5, 15.38, 9.54, 17.42, 19.58, 5.57, 7.73, 15.61, 9.77, 17.65, 19.81, 10.47, 18.35, 20.51, 22.55, 6.05, 8.21, 16.09, 10.25, 18.13, 20.29, 10.95, 18.83, 20.99, 23.03, 11.18,19.06, 21.22, 23.26, 23.96, 11.66, 19.54, 21.7, 23.74, 24.44, 24.67, 25.15} now you can even write it in a nicer form: Thread[List[total,thethickness]] { {f[1], 0.48}, {f[2], 0.71}, {f[3], 1.41},... {f[1, 3], 1.89}, {f[1, 4], 3.93}, ... {f[1, 2, 3], 2.6} ... {f[1, 3, 4, 5, 6], 24.44}, {f[2, 3, 4, 5, 6], 24.67}, {f[1, 2, 3, 4, 5, 6], 25.15} } good luck -------------------------------------------- Pasquale Nardone * * Universiti Libre de Bruxelles * CP 231, Sciences-Physique * Bld du Triomphe * 1050 Bruxelles, Belgium * tel: 650,55,15 fax: 650,57,67 (+32,2) * ,,, (o o) ----ooO-(_)-Ooo----