Re: Urgent( Problem with Mathematica-5)
- To: mathgroup at smc.vnet.net
- Subject: [mg74734] Re: Urgent( Problem with Mathematica-5)
- From: "Jean-Marc Gulliet" <jeanmarc.gulliet at gmail.com>
- Date: Mon, 2 Apr 2007 07:02:07 -0400 (EDT)
- References: <964e98130704010507h606329dfh5eef1f957a6ad314@mail.gmail.com>
On 4/1/07, Malaka Thillakaratne <malakaext at gmail.com> wrote: > > > > > Hi Jean-Marc, > > Cantor Function > 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]]] >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}] > > > > Hi,My friend Neeleke requested you to correct the above program for me and > you had been so generous to send me the corrected code and it is given > below. > But unfortunately when i tried to run it using Mathematica-5 it gave an > error massage as > "SetDelayed::Write:Tag Connect in Connect[{a_,b_}] is Protected" > > Please be good enough to corret this and send the corrected code to me asap. > > The code you had sent to Neelaka is given below for you convenience. > > 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}]; > > I look forward to here from you soon as I have to submit this as my final > year project in two days time. > 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 pitfalls [1]. HTH, Jean-Marc [1] "Part 1: A Practical Introduction to Mathematica", _The Mathematica Book_, http://documents.wolfram.com/mathematica/book/section-1