       Cantor Function problem

• To: mathgroup at smc.vnet.net
• Subject: [mg74596] Cantor Function problem
• From: "Neelaka Seneviratne" <neelaka at gmail.com>
• Date: Tue, 27 Mar 2007 04:07:54 -0500 (EST)

```hi,

i am not a member of this group. but i have a difficulty in Mathematica that
you may be able to help with.
resolve it.
this is for a friend of mine who wants to generate the cantor function for
his BSc final year project.

thank you very much
neelaka seneviratne

spawn[{a_Rational, b_rational}] :=
Block [{w=(b-a)/3}, {{a-2w, a-w}, {b+w, b+2w}}]
spawn [intervals_list] := Flatten[Map[spawn, intervals], 1 /;
Length[intervals[]] >1

removedintervals[n_]:=
Flatten[NestList[spawn, {{1/3, 2/3}}, n-1], 1]

f = 1;
f[x_] := f[3x]/2   /; x<=1/3;
f[x_] := 1-f[1-x] /; 2/3<=x;

connect [{a_, b_}] := Block [{y=f[a]}, Line[{{a,y}, {b,y}}]]

CantorFunction[levels_] := show[Graphics[{Thickness[.001],
Map[connect, removedintervals[levels]]}],
Axes-> {0,0}, Ticks->{N[Range[0., 1, 1/9], 3], Automatic}]

```

• Prev by Date: Thread function now working as expected
• Next by Date: Sequence as a universal UpValue