> with(plots,polygonplot3d,display3d): # CantorSequence constructs a list containing the sequence p^i i=0, 1, # ... N-1. # The value p should be less than 1/2. CantorSequence(4,1/3) will # construct # the first four elements of the sequence used to construct the Cantory # 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 approximation of the Cantor function on the 2D # Cantor set # defined by the sequence cseq. NOTE: unlike GraphPsiHat for the 1D # sets, this version # displays the graph. GraphPsiHat(CantorSequence(6,1/3)); will display # the graph of an # approximation of the Cantor ternary function on the 2D ternary set. > GraphPsiHat := proc(cseq:list) > local n,k,k1,k2,crds,crds2,these,rect1,rect2,h,farbe: > global all,plotme: > all := []: > crds := [0,1]: > for n from 2 to nops(cseq) do > crds2 := []: > these := []: > 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]]: > these := [op(these), > [crds[2*k+1],crds[2*k+1]+cseq[n],crds[2*k+2]-cseq[n],crds[2*k+2]] ]: > od: > crds := crds2: > for k1 from 1 to nops(these) do > for k2 from 1 to nops(these) do > h := ((2*k1-1)/2^(n-1)+(2*k2-1)/2^(n-1))/2: > all := [op(all), [ h,these[k1],these[k2] ]]: > od: > od: > od: > plotme := {}: > for n from 1 to nops(all) do > farbe := COLOUR(RGB,1,op(1,all[n]),op(1,all[n])): > rect1 := [ > [all[n][2][2],all[n][3][1],all[n][1]],[all[n][2][3],all[n][3][1],all[n > ][1]],[all[n][2][3],all[n][3][4],all[n][1]],[all[n][2][2],all[n][3][4] > ,all[n][1]] ]: > rect2 := [ > [all[n][2][1],all[n][3][2],all[n][1]],[all[n][2][4],all[n][3][2],all[n > ][1]],[all[n][2][4],all[n][3][3],all[n][1]],[all[n][2][1],all[n][3][3] > ,all[n][1]] ]: > plotme := plotme union {polygonplot3d(rect1,color=farbe,style=patch), > polygonplot3d(rect2,color=farbe,style=patch) }: > od: > display3d(plotme): > end: # Display an approximation of the Cantor function on the 2D ternary set > GraphPsiHat(CantorSequence(3,1/3)); >