在Mathematica中使用RegionProduct绘制康托尔集合

在Mathematica中, 内置了函数RegionProduct。这个函数能用来绘制康托尔集合。这个函数的基本意思是指

RegionProduct[reg1,reg2,…] 
表示区域reg1, reg2, ….的笛卡尔积

使用这个函数,我们编写三个函数:

ClearAll[cantorrule, cantorRegion, cantorDust] 
(*康托尔集的生成法则*) 
cantorrule[s_: 1/3] := ReplaceAll[{a_, b_} :> {{a, a + (b - a) (1 - s)/2}, {a + (b - a) (1 + s)/2, b}}]; 
(*生成一维的用来做乘积的区域*)
 cantorRegion[s_: 1/3][t_Integer?NonNegative] := MeshRegion[ List /@ Flatten[Nest[Apply[Join]@*Map[cantorrule[s]], {{0, 1}}, t]], Line @ Partition[Range[2^(t + 1)], 2]] 
(*显示成像区域*)
 cantorDust[s_: 1/3][t_Integer?NonNegative, dim_: 1] := RegionProduct @@ Table[cantorRegion[s][t], dim]
Labeled[Grid[Transpose @ {Show[cantorDust[][#, 1], ImageSize -> Medium] & /@ Range[3], Show[cantorDust[][#, 2], ImageSize -> Medium] & /@ Range[3], Show[cantorDust[][#, 3], ImageSize -> Medium] & /@ Range[3]}, Dividers -> All], Style["s = 1/3", 36], Top]

也可以改变s的值为1/4和5/12等,来试一下显示效果。

Labeled[Grid[{Prepend[Style["s", 24]][Style["t = " <> ToString@#, 16] & /@ {1, 2, 3}], Prepend[Style["1/4", 16]][ Show[cantorDust[1/4][#, 1], ImageSize -> Medium] & /@ Range[3]], Prepend[Style["1/3", 16]][ Show[cantorDust[1/3][#, 1], ImageSize -> Medium] & /@ Range[3]], Prepend[Style["5/12", 16]][ Show[cantorDust[5/12][#, 1], ImageSize -> Medium] & /@ Range[3]]}, Dividers -> All], Style["dim=1", 36], Top]

Labeled[Grid[{Prepend[Style["s", 24]][ Style["t = " <> ToString@#, 16] & /@ {1, 2, 3}], Prepend[Style["1/4", 16]][ Show[cantorDust[1/4][#, 2], ImageSize -> Medium] & /@ Range[3]], Prepend[Style["1/3", 16]][ Show[cantorDust[1/3][#, 2], ImageSize -> Medium] & /@ Range[3]], Prepend[Style["5/12", 16]][ Show[cantorDust[5/12][#, 2], ImageSize -> Medium] & /@ Range[3]]}, Dividers -> All], Style["dim=2", 36], Top] Export[ FileNameJoin[ {NotebookDirectory[], "cantor_dust_2d_collection.png"} ], % ]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值