MathGroup Archive 2007

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

Search the Archive

Re: Re: Cantor Function problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74733] Re: [mg74605] Re: Cantor Function problem
  • From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 2 Apr 2007 07:01:36 -0400 (EDT)
  • References: <euanne$duk$1@smc.vnet.net> <200703280639.BAA20399@smc.vnet.net>

On 4/1/07, Malaka Thillakaratne <malakaext at gmail.com> wrote:
> Hi,
> Im neelaka's friend and i tried the code you sent to neelaka to generate the
> cantor function.but unfortunately it gave an error message as
> ""SetDelayed::Write:Tag Connect in Connect[{a_,b_}] is Protected"
> (I tried the program using methematica-5 )
> Please be kind enough to find where the problem is ,and send me the solution
> asap as i have to complete my final year project.Hope you would help me in
> this regard.
> Thank you.

The corrected code I gave you did work on my system and it will works
on yours if you enter it (or cut and paste it) *verbatim*. In other
words, you must respect the case of the characters for Mathematica
distinguishes a "c" (lowercase c) from a "C" (uppercase c).

?Connect

==> "Connect is a setting for the LinkMode option of LinkOpen.
LinkMode->Connect causes a link to be created that will connect to a
link listening on a named port."

Connect is a system function and Mathematica complains about your
attempt to redefine it. Use connect (lowercase only) as given in my
previous message.

It might be worse reading, or at least browsing, the first part of
_The Mathematica Book_ to avoid such pitfails [1].

HTH,
Jean-Marc

[1]  "Part 1: A Practical Introduction to Mathematica", _The Mathematica Book_,
http://documents.wolfram.com/mathematica/book/section-1

> On 3/28/07, Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com> wrote:
> > 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
> >
> >
> >
>
>
>
> --
> Malaka The Greatest


  • Prev by Date: Re: verification
  • Next by Date: Re: verification
  • Previous by thread: Re: Re: Finding unknown parameters using Mathematica
  • Next by thread: Re: Cantor Function problem