MathGroup Archive 2000

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

Search the Archive

Re: Cantor set plot, Dirichlet function plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg23583] Re: [mg23579] Cantor set plot, Dirichlet function plot
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sun, 21 May 2000 18:12:51 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

It seems to me that the problem of representing such things
graphically has more to do with human psychology than mathematics. The
function I defined is a  "finer" approximation to the function that you
asked for than the one you found on MathSource, but it is actually harder to
use it to make a convincing visualization. The problem is that you are
selecting a finite number of points out of a continuum, and the difficulty
is to do so in a way that will seem "enlightening".

Essentially the same applies to the Cantor set. There is a pretty good
discussion of this in Stan Wagon's "Mathematica in Action". Rather than try
to write my own code this time I just extracted his (and converted all the
global variables to local ones). There are many other interesting  and
related constructions in his book(also the code below is explained quite
clearly).



CantorSet[x_Rational, y_Rational, n_] :=
  Module[{spawn, rem,dep},
   spawn[{a_Rational, b_Rational}] :=
     Module[{w = (b - a)/3}, {{a - 2*w, a - w},
       {b + w, b + 2*w}}]; spawn[intervals_List] :=
     spawn /@ intervals;
 rem = NestList[spawn, {x, y},
      n]; Show[Graphics[
      {Table[{AbsoluteThickness[4 - (4 - 0.4)*(dep - 1)/
             n], (Line[{{#1[[1]], n - dep}, {#1[[2]],
              n - dep}}] & ) /@ Partition[Union[{0, 1},
            Cases[rem, _Rational, dep]], 2]},
        {dep, 1, n}]}], FrameTicks ->
      {({#1, BaseForm[N[#1], 3]} & ) /@ (Range[0, 9]/9.),
       None, None, None}, Frame -> True,
     PlotRange -> {-1, n}, AspectRatio -> 1/4]; ]

Now just evaluate 

CantorSet[1/3, 2/3, 4]

and so on.


-- 
Andrzej Kozlowski
Toyama International University
JAPAN

http://platon.c.u-tokyo.ac.jp/andrzej/
http://sigma.tuins.ac.jp/


on 5/21/00 6:44 AM, David Ong at do226 at is2.nyu.edu wrote:

> 
> Thanks Andrzej,
> 
> The code for the Dirichlet like function plot wasn't quite what I had
> expected. However, I am glad to have another method to deal with these
> sorts of functions.
> 
> Here is some code from Gabriel Chjnevert's  "Ploting Monster's of Real
> variables", which I got from math source. Now I am looking for a simple
> way to
> plot an approximation to the Cantor set and would welcome suggestions.
> 
> n = 150;
> points = Union @@ Table[{p/q, 1/Denominator[p/q]}, {q, n}, {p, q - 1}];
> 
> ListPlot[points, PlotRange -> {0, .51}]
> 
> David
> 
> 
> 
> 
> 
> 
> 
> 
> On Sun, 21 May 2000, Andrzej Kozlowski wrote:
> 
>> Sorry, the definition should of course have been:
>> 
>> f[x_] := If[IntegerQ[Numerator[Rationalize[N[x]]]],
>> 1/Denominator[Rationalize[x]], 0]
>> 
>> on 00.5.21 0:07 AM, Andrzej Kozlowski at andrzej at tuins.ac.jp wrote:
>> 
>>> This is of course a somewhat different matter. One can define a reasonable
>>> "simulation" of this function and in principle plot its graph but I think it
>>> will be  hard to see anything interesting. The definition is simple enough:
>>> 
>>> f[x_] := If[IntegerQ[Numerator[Rationalize[N[x]]]],
>>> Denominator[Rationalize[x]], 0]
>>> 
>>> f is a good approximation to what you want:
>>> 
>>> In[3]:=
>>> f[Pi]
>>> 
>>> Out[3]=
>>> 0
>>> 
>>> In[4]:=
>>> f[1.4]
>>> 
>>> Out[4]=
>>> 5
>>> 
>>> In[5]:=
>>> f[Sqrt[2]]
>>> 
>>> Out[5]=
>>> 0
>>> 
>>> Unfortunately it is hard to get a meaningful graph. You could try using
>>> ListPlot and do something like:
>>> 
>>> In[6]:=
>>> l1 = Table[{x, f[x]}, {x, 3.0, Pi + 0.1, 0.001}];
>>> 
>>> In[7]:=
>>> l2 = Table[{x, f[x]}, {x, Pi - 0.14, Pi + 0.1, 0.001}];
>>> 
>>> In[8]:=
>>> ListPlot[Union[l1, l2]]
>>> 
>>> But the result does not seem t me to be very instructive. In principle I
>>> think
>>> what I wrote in my first reply still holds and I do not think computers are
>>> suitable tools for investigating this sort of phenomena.
>>> 
>>> on 00.5.20 11:02 PM, David Ong at do226 at is2.nyu.edu wrote:
>>> 
>>>> 
>>>> Sorry, I misstated the function.
>>>> f(x)=1/q when x is an element of p/q in lowest terms and f(x)=0
>>>> otherwise. This is a strange looking function because it is continous at
>>>> every irrational and discontinuous at every rational.
>>>> 
>>>> On Sat, 20 May 2000, Andrzej Kozlowski wrote:
>>>> 
>>>>> The problem with your question is that the concept of an "irrational
>>>>> number"
>>>>> does not really make sense in relation to a present day computer. Neither
>>>>> Mathematica not any other computer program can distinguish between
>>>>> rationals
>>>>> and irrationals and no sensible concept of an "irrational" number can be
>>>>> implemented. Of course you could invent a new  Mathematica function,
>>>>> IrrationalQ, an tell Mathematica it should return True for some well known
>>>>> irrationals, e.g. Pi, E, Sqrt[2], this would not get you very far. It is
>>>>> well known that there can be no algorithm which would decide whether any
>>>>> given (constructible) real number is rational or not.  One can easily
>>>>> generate arbitrary long sequences consisting entirely of irrationals,
>>>>> e.g.,
>>>>> anything of the form p^(1/n) where p is a prime and n a  positive integer,
>>>>> or  any real number of the form (1-x^n)^(1/n), where x is any rational
>>>>> s.t.
>>>>> 0<x<1, and n a positive integer>2, but no  computer can check this.
>>>>> 
>>>>> However, in spite of all the above,  it is very easy to  plot your
>>>>> function.
>>>>> You simply take the union of the graph of 1/x  and the real axis (you must
>>>>> exclude 0 since your function has no value there). This is as good an
>>>>> approximation as one can ever hope for!
>>>>> 
>>>>> 
>>>>> -- 
>>>>> Andrzej Kozlowski
>>>>> Toyama International University
>>>>> JAPAN
>>>>> 
>>>>> http://platon.c.u-tokyo.ac.jp/andrzej/
>>>>> http://sigma.tuins.ac.jp/
>>>>> 
>>>>> on 5/20/00 4:10 PM, David Ong at do226 at is2.nyu.edu wrote:
>>>>> 
>>>>>> Hi, 
>>>>>> 
>>>>>> Would anyone know of an easy way to plot some approximation of this
>>>>>> variant of the Dirichlet function?
>>>>>> f(x)=1/x if x is an element of the rationals and 0 if x is not an element
>>>>>> of the rationals.
>>>>>> 
>>>>>> 
>>>>>> 
>>>>> 
>>>>> 
>>>> 
>> 
>> -- 
>> Andrzej Kozlowski
>> Toyama International University
>> JAPAN
>> 
>> http://platon.c.u-tokyo.ac.jp/andrzej/
>> http://sigma.tuins.ac.jp/
>> 
> 
> 




  • Prev by Date: Re: Question of function for hexahedron
  • Next by Date: Re: Cantor set plot, Dirichlet function plot
  • Previous by thread: Cantor set plot, Dirichlet function plot
  • Next by thread: Re: Cantor set plot, Dirichlet function plot