> with(plots,display): # CantorSequence generates a list that contains the first N elements of # the sequence # p^i i=0, 1, . . . The value p should be less than 1/2. # CantorSequence(4,1/3) will generate the first four elements of the # sequence used to # construct the Cantor ternary set. > CantorSequence := proc(N:integer,p) > local i,lst: > lst := []: > for i from 0 to N-1 do > lst := [op(lst),p^i]: > od: > lst: > end: # GraphPsiHat draws the graph of the Cantor function based on the # sequence cseq # in the color farbe. cseq should be a list (such as those created by # CantorSequence), # and farbe should be a legitimate Maple color (e.g., red, blue, # COLOR(RGB,.2,.2,.2)). # GraphPsiHat(CantorSequence(4,1/3),red) will draw an approximation of # the # Cantor ternary function. # NOTE: GraphPsiHat will return a plot object. You must use display to # view the graph. > GraphPsiHat := proc(cseq:list,farbe) > local n,k,crds,crds2: > global all,all2: > all := []: > all2:={}: > crds := [0,1]: > for n from 2 to nops(cseq) do > crds2 := []: > for k from 0 to nops(crds)/2-1 do > crds2 := > [op(crds2),crds[2*k+1],crds[2*k+1]+cseq[n],crds[2*k+2]-cseq[n],crds[2* > k+2]]: > all := [op(all), > [(2*(k+1)-1)/2^(n-1),crds[2*k+1]+cseq[n],crds[2*k+2]-cseq[n]] ]: > od: > crds := crds2: > od: > for k from 1 to nops(all) do > all2 := all2 union > {plot(op(1,all[k]),x=op(2,all[k])..op(3,all[k]),color=farbe)}; > od: > all2: > end: # Draw a the Cantor ternary function in blue > display(GraphPsiHat(CantorSequence(6,1/3),blue)); # Display four Cantor functions together. > bild := []: > for i from 0 to 3 do > bild := > [op(bild),GraphPsiHat(CantorSequence(4,1/(3+i)),COLOR(RGB,i/3,0,(3-i)/ > 3))]: > od: > display(bild); >