这里,介绍一下用Mathematica处理数论问题的内容!
工具/原料
电脑
Mathematica
基础
1、绘制一个没有明确方向的图:Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}]图里的顶点分别是1、2、3,但是省略了标签!
2、再来绘制一个有向图:Graph[{1 -> 2, 2 -> 3, 3 -> 1}]
3、改变边和顶点的样式:Graph[{1 <-> 2, 2 <->挢旗扦渌; 3, 3 <-> 1荑樊综鲶,1 <-> 5}, VertexStyle -> Orange, EdgeStyle -> Green]Vertex是顶点的意思,Edge是边的意思!
4、还可以把样式封装起来:Graph[{1, 2, Style[3, Red],Style[6,Green],Style[5,Blue]}, { 2 <-> 3, Style[3 <-> 1, Blue], Style[5<-> 1, Yellow], Style[6<->2, Red], Style[2 <-> 1, Green]}]
5、给图的顶点和边添加标签,还可以对标签设置不同的样式!蘅荫酸圉Graph[{1 <-> 2, 2 <-> 3,Labeled[3 媪青怍牙<-> 1, Style[ "这是边的标签",Red,Opacity[0.5]]],1 <-> 5}, VertexStyle -> Yellow, EdgeStyle -> Green,VertexLabels -> "Name"]Opacity是透明度的意思!
应用一例
1、求前100个数字的平方,除以17的余数,并把这个映射画成图!先做列表:Table[i -> Mod[i^2, 17], {i, 100}]再构造图:Graph[%]
2、这是换了一个除数的结果:Graph[Table[i -> Mod[i^2, 69], {i, 100}]]
3、我们可以给出各顶点的标签,这样看着容易一些:Graph[Table[i -> Mod[i^2, 69], {i, 100}],VertexLabels -> "Name"]
应用二例
1、列举以plot开头的所有英文单词:words = DictionaryLookup["plot*"]
2、把相互之间比较接近的单词,用箭头连起来:Flatten职邗珩垃[Map[(Thread[# \[DirectedEdge] DeleteCases[Nearest[words, #, 3], 垆杪屑丝#]]) &, words]]
3、作图,并显示标签:Graph[%, VertexLabels -> "Name", ImageSize ->365]