相关疑难解决方法(0)

如何在Mathematica 8中以编程方式访问有关"Graph"对象的信息?

我正在尝试访问GraphMathematica 8中对象内的信息.出于某种原因,该Part命令似乎不起作用.

myGraph 是我想要访问的对象.

下面的第一行显示myGraph.其他人则用来检查它.

myGraph

myGraph // FullForm  
myGraph // InputForm  
myGraph // OutputForm    
myGraph[[1]]
myGraph[[2]]  
Run Code Online (Sandbox Code Playgroud)

myGraph

为什么不myGraph[[1]]回来List[1,3,4,2,5] ?[我检查了2级以防万一Graph被一些隐形包装包裹起来. Level[myGraph,1],简单地回来{}.并FullForm[myGraph][[1]]返回图表本身的图片.

我必须忽略一些明显的东西.


编辑

这是我用来生成图表的代码.其中大部分与手头的问题无关.但至少你会使用我正在使用的相同代码.

ClearAll[edges, compatibleQ, adjacentCourses, g];
edges[w_, b_] := 
 Most /@ Accumulate /@ 
   Flatten[Permutations[#] & /@ IntegerPartitions[w, All, b], 1]

compatibleQ[j_, k_, edg_] := 
 If[Intersection[edg[[j]], edg[[k]]] == {}, {j, k}, False]

adjacentCourses[edg_] := 
 Module[{len = Length[edg]},
  Cases[Flatten[Table[compatibleQ[j, k, edg], {j, len}, {k, j, len}], 
    1], …
Run Code Online (Sandbox Code Playgroud)

wolfram-mathematica mathematica-8

7
推荐指数
3
解决办法
519
查看次数

GraphPlot Graphic中的VertexCoordinate规则和VertexList

是否有任何方法可以从GraphPlot生成的图形的(FullForm或InputForm)中抽象出GraphPlot应用于VertexCoordinate规则的顶点顺序?我不想使用GraphUtilities函数VertexList.我也知道GraphCoordinates,但这两个函数都适用于图形,而不是GraphPlot的图形输出.

例如,

gr1 = {1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 1};
gp1 = GraphPlot[gr1, Method -> "CircularEmbedding", 
   VertexLabeling -> True];

Last@(gp1 /. Graphics[Annotation[x___], ___] :>  {x})
Run Code Online (Sandbox Code Playgroud)

给出以下六个坐标对的列表:

VertexCoordinateRules - > {{2.,0.866025},{1.5,1.723205},{0.5,1.723205},{0.,0.866025},{0.5,1.3349*10 ^ -10},{1.5,0.}}

我如何知道哪个规则适用于哪个顶点,我可以确定这与VertexList [gr1]给出的规则相同吗?

例如

 Needs["GraphUtilities`"];
gr2 = SparseArray@ 
      Map[# -> 1 &, EdgeList[{2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6}]];

    VertexList[gr2]
Run Code Online (Sandbox Code Playgroud)

给出{1,2,3,4,5}

但......

    gp2 = GraphPlot[gr2, VertexLabeling -> True, 
      VertexCoordinateRules -> 
       Thread[VertexList[gr1] -> …
Run Code Online (Sandbox Code Playgroud)

wolfram-mathematica

5
推荐指数
2
解决办法
2235
查看次数

Graph []切断了Mathematica中的顶点标签

Graph[]有倾向于切断Mathematica中的顶点标签.我正在寻找一个强大的解决方法.

例:

Graph[{1 -> 2, 2 -> 3, 3 -> 1}, VertexLabels -> "Name"]
Run Code Online (Sandbox Code Playgroud)

Graph []切断标签'2'

我目前的解决方法:

SetOptions[Graph, ImagePadding -> 12]
Run Code Online (Sandbox Code Playgroud)

这不稳定,因为ImagePadding需要根据标签大小手动调整值.

graphics wolfram-mathematica mathematica-8

5
推荐指数
1
解决办法
1065
查看次数

三个矩阵的乘积最终得到奇数块矩阵?

在下面的mathematica代码中

a1 = {{0, -I}, {I, 0}}
a2 = {{0, 1}, {1, 0}}
a3 = {{1, 0}, {0, -1}}
c = I*a1*a2 // MatrixForm
d = c*a3 // MatrixForm
Run Code Online (Sandbox Code Playgroud)

d的显示显示为2×2矩阵,其中1,1和2,2元素本身是2x2矩阵,而我希望它是一个普通的2x2标量矩阵?

wolfram-mathematica matrix-multiplication

4
推荐指数
2
解决办法
2458
查看次数