首页 > 代码库 > Mathematica 迭代函数

Mathematica 迭代函数

学习Mathematica迭代函数的几个画图例子:

1.三角形沿着某一点旋转

verticse = {{0, 0}, {1, 0}, {1/2, Sqrt[3]/2}};tri = Line[verticse /. {a_, b__}->{a, b, a}];Graphics[tri]

rotation[gr_] := Rotate[gr, Pi/13, {1, 1}];Graphics[NestList[rotation, tri, 30]]

2.绘出迭代平移之后的三角形

translation[gr_] := Translate[gr, verticse];Graphics[{RGBColor[0.32, 0.77, 1.], NestList[translation, tri, 5]}]

3.Sierpinski Triangle

SierpinskiTriangle[iter_, opts : OptionsPattern[Graphics]] :=Module[{vertics, vecs},vertics = N[{{0, 0}, {1, 0}, {1/2, 1}}];vecs = 0.5 vertics;Graphics[{Blue, Nest[{Blue, Translate[Scale[#, 0.5, {0., 0.}], vecs]} &,Polygon[vertics], iter]}, opts]] SierpinskiTriangle[8, ImageSize -> 512]

参考资料:

  • http://reference.wolfram.com/mathematica/ref/NestList.html
  • http://reference.wolfram.com/mathematica/ref/Rotate.zh.html
  • http://reference.wolfram.com/mathematica/ref/Translate.html
  • http://reference.wolfram.com/mathematica/ref/Module.html
  • http://en.wikipedia.org/wiki/Sierpinski_triangle
  • http://mathworld.wolfram.com/SierpinskiSieve.html

Mathematica 迭代函数