Approximating the Cantor Function

Helmut Knaust, Department of Mathematical Sciences, UTEP, El Paso TX 79968
hknaust@utep.edu
9/29/09

First approach

m[0]={Line[{{0,0},{1,0}}]};
m[n_]:=
m[n]=Flatten[m[n-1]/.Line[{a_,b_}]->{Line[{a,{a[[1]]+1/3^n,a[[2]]}}], Line[{{a[[1]]+2/3^n,a[[2]]+1/2^n},{b[[1]],b[[2]]+1/2^n}}]}]
Manipulate[Show[Graphics[{Red,Thick,m[n]}],AxesLabel->{Row[{Subscript["C",n]}],"[0,1]"},PlotRange->{0,1},PlotRangePadding->{0.05},BaseStyle->{16,Bold},ImageSize->500,Axes->True,Ticks->{Table[k/9,{k,0,9}],Table[k/8,{k,0,8}]}],{n,0,10,1}]

Second approach

l[0]={Line[{{0,0},{1,1}}]};
l[n_]:=l[n]=Flatten[l[n-1]/.Line[{a_,b_}]->{Line[{a,{a[[1]]+1/3^n,a[[2]]+1/2^n}}],Line[{{a[[1]]+2/3^n,a[[2]]+1/2^n},b}]}]
Manipulate[Show[Graphics[{Blue,Thick,l[n]}],AxesLabel->{Row[{Subscript["C",n]}],"[0,1]"},PlotRange->{0,1},PlotRangePadding->{0.1},BaseStyle->{16,Bold},ImageSize->500,Axes->True,Ticks->{Table[k/9,{k,0,9}],Table[k/8,{k,0,8}]}],{n,0,8,1}]