MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Cantor Function problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74605] Re: Cantor Function problem
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Wed, 28 Mar 2007 01:39:51 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <euanne$duk$1@smc.vnet.net>

Neelaka Seneviratne wrote:
> hi,
> 
> i am not a member of this group. but i have a difficulty in Mathematica that
> you may be able to help with.
> I got the following program from a book but it doesnt work. please help to
> 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}] :=
-----------------------^
Syntax error : must be Rational

>   Block [{w=(b-a)/3}, {{a-2w, a-w}, {b+w, b+2w}}]
> spawn [intervals_list] := 
-------------------^
Syntax error : must be List

> Flatten[Map[spawn, intervals], 1 /;
----------------------------------^
Missing close square bracket

>               Length[intervals[[1]]] >1
> 
> removedintervals[n_]:=
>   Flatten[NestList[spawn, {{1/3, 2/3}}, n-1], 1]
> 
> f[0] = 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}]
----^^^^^
Should be AxesOrigin

You will find below your code with the corrections added.

In[1]:=
spawn[{a_Rational, b_Rational}] := Block[{w = (b - a)/3},
     {{a - 2*w, a - w}, {b + w, b + 2*w}}];

spawn[intervals_List] := Flatten[spawn /@ intervals, 1] /;
     Length[intervals[[1]]] > 1;

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

f[0] = 1;
f[x_] := f[3*x]/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[0.001],
       connect /@ removedintervals[levels]}], AxesOrigin -> {0, 0},
     Ticks -> {N[Range[0., 1, 1/9], 3], Automatic}];

In[9]:=
CantorFunction[5];

[...graphic deleted...]

Regards,
Jean-Marc



  • Prev by Date: Re: Cantor Function problem
  • Next by Date: Re: Re: Definite Integration in Mathematica
  • Previous by thread: Re: Cantor Function problem
  • Next by thread: Sequence as a universal UpValue