2010-11-05 59 views
6

以下代码创建了某个计算的图表。我的问题是,尽管分母中的术语顺序很好,但在应用Plus之后,它们会被任意地重新排列。任何建议如何强制原始订单被保留?防止“Plus”重新排列东西

http://yaroslavvb.com/upload/ind-sets-grid.png

 
r[i_] := Floor[(i - 1)/n] + 1; 
c[i_] := Mod[i, n, 1]; 
adj[a_, b_] := Abs[r[a] - r[b]] + Abs[c[a] - c[b]] == 1; 
indsetQ[s_] := Not[Or @@ (adj @@@ Subsets[s, {2}])]; 
indsets[k_] := Select[Subsets[Range[n^2], {k}], indsetQ]; 
twoColorGraph[g_, seen_, lbl_] := Module[{radius = .22}, 
    vcoords = # -> {c[#], n - r[#]} & /@ Range[n^2]; 
    fv = Function[{p, v}, {EdgeForm[Thick], 
     If[MemberQ[seen, v], Pink, White], Disk[p, radius]}]; 
    GraphPlot[g, VertexLabeling -> True, VertexRenderingFunction -> fv, 
    PlotLabel -> Style[lbl, 20], LabelStyle -> Directive[Bold], 
    VertexCoordinateRules -> vcoords, ImageSize -> 80] 
    ]; 
n = 2; 
g = Array[Boole[adj[#1, #2]] &, {n^2, n^2}]; 
weight[set_] := Times @@ (Subscript[\[Lambda], c[#], r[#]] & /@ set); 
denominator = 
    twoColorGraph[g, #, weight[#]] & /@ 
    Join @@ (indsets[#] & /@ Range[2]); 
numerator = twoColorGraph[g, {1}, weight[{1}]]; 
Style[numerator/(Plus @@ denominator), FontSize -> 30] 
+0

这是一个重复,意图,如果不是形式,另一个问题(http://stackoverflow.com/questions/3947071/controllingorder-of-variables-in-an-expression)。否则,我会给你一个单独的图形+1。什么是计算? – rcollyer 2010-11-05 19:38:36

+0

是的,这是相似的。那里的建议是定义像“myPlus”这样的不是无序的自己的功能,但是我怎样才能让它与“Plus”一样呈现? – 2010-11-05 19:42:07

+0

计算是在有限网格(即具有硬核自排斥和硬核对相互作用的宏规范气体)上找到每个现场占据核心排斥性局部气体的概率 – 2010-11-05 20:12:19

回答

5

诀窍格式化像myPlus看起来像Plus输出是使用Format。这里有一个简单的例子,让你开始:

然后,你会直观地看到在笔记本电脑是什么:

In[7]:= x = myPlus[3, 2, 1] 
Out[7]= 3+2+1 

...但x仍会有头myPlus

下面是从进入更多详细的格式化输出,运算符优先级本文档的tutorial

希望帮助!

+1

+1,我试图用'Notation'做到这一点,并且它失败了。我忘了直接看'格式'。 – rcollyer 2010-11-05 20:52:55

+0

我试图将'Interpretation'与您的答案结合起来,以便它可以被正确地复制和粘贴,但遇到问题。请参阅SO问题http://stackoverflow.com/q/4112299/421225 – Simon 2010-11-06 07:18:57