PROGRAM iterate_map ! iterate logistic map CALL set_up_windows(#1,#2) DO CALL initial(x,r,#1,#2,flag$) CALL map(x,r,#1,#2,flag$) LOOP until flag$ = "stop" END SUB initial(x0,r,#1,#2,flag$) WINDOW #2 INPUT prompt "growth parameter (0 < r <= 1) = ": r LET x0 = 0.3 CLEAR BOX LINES 0,1000,0,1 SET CURSOR 1,2 PRINT "r ="; r LET flag$ = "" END SUB SUB set_up_windows(#1,#2) OPEN #1: screen 0,1,0,0.5 ! text OPEN #2: screen 0,1,0.5,1 ! graphics LET nmax = 1000 LET margin = 0.01*nmax SET WINDOW -margin,nmax+margin,-0.01,1.01 END SUB SUB map(x,r,#1,#2,flag$) LET iterations = 0 DO LET x = 4*r*x*(1 - x) ! iterate map LET iterations = iterations + 1 ! number of iterations WINDOW #1 SET COLOR "black/white" PRINT USING "#.######": x; ! period doubling implies convenient to start new line ! every 2^n iterations, where n = 2 or 3. IF mod(iterations,8) = 0 then PRINT ! new line WINDOW #2 SET COLOR "red" PLOT iterations,x IF key input then CALL change(#1,#2,flag$) LOOP until flag$ = "stop" or flag$ = "change" WINDOW #1 PRINT PRINT "number of iterations = "; iterations END SUB SUB change(#1,#2,flag$) GET KEY k IF (k = ord("c")) or (k = ord("C")) then LET flag$ = "change" SET COLOR "black/white" ELSE IF (k = ord("s")) or (k = ord("S")) then LET flag$ = "stop" END IF END SUB