# Visualization of Cantor set by Mathematica or Maple!

We all know what it is the Cantor set. The Cantor set is created by repeatedly deleting the open middle thirds of a set of line segments. One starts by deleting the open middle third $(\frac{1}{3}, \frac{2}{3})$ from the interval $[0, 1]$, leaving two line segments: $[0, \frac{1}{3}] ∪ [\frac{2}{3}, 1]$. Next, the open middle third of each of these remaining segments is deleted, leaving four line segments: $[0, \frac{1}{9}] ∪ [\frac{2}{9}, \frac{1}{3}] ∪ [\frac{2}{3}, \frac{7}{9}] ∪ [\frac{8}{9}, 1]$. This process is continued ad infinitum, where the nth set. The Cantor ternary set contains all points in the interval $[0, 1]$ that are not deleted at any step in this infinite process. An explicit formula for the Cantor set is $$C=[0,1]\bigcup_{m=1}^{\infty}\bigcup_{k=0}^{3^{m-1}-1}(\frac{3k+1}{3^m},\frac{3k+2}{3^m})$$

I know Maple just for doing some calculus and some basic modeling. I am asking if someone can note me a program in which we visualize the Cantor set. As I don't know if this job can be done in Maple, I added Mathematica in the title. Maybe its environment is more powerful than Maple in this question. Thanks.

-

– sydeulissie Jul 8 '12 at 8:52

## 2 Answers

The Cantor $\frac13$ set is kind of hard to visualize, since it has infinitely many points but zero Lebesgue measure. The best visualization I could think of was to plot an approximation of its indicator function:

````> f := a -> [seq(x/3, x in a), seq((2+x)/3, x in a)]:
> cantor := n -> (f@@n)([0,1]):
> delta2plot := points -> [seq(seq([x,y], y in [0,1,0]), x in points))]:
> plots:-listplot(delta2plot(cantor(5)), color=gray, view=[0..1,0..1]);
````

$\hspace{110px}$

-

For Mathematica see

-

Thanks. I didn't know it was done before! – Babak S. Jul 5 '12 at 18:52
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 7, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9355871677398682, "perplexity_flag": "middle"}