PROGRAM graph_sol ! graphical solution for trajectory of logistic map CALL initial(x,r,iterate) CALL draw_function(r,iterate) CALL trajectory(x,r,iterate) ! press any key to stop END SUB initial(x0,r,iterate) INPUT prompt "control parameter r = ": r INPUT prompt "initial value of x = ": x0 INPUT prompt "iterate of f(x) = ": iterate CLEAR PRINT "r ="; r END SUB SUB draw_function(r,iterate) DECLARE DEF f LET nplot = 200 ! # of points at which function computed LET delta = 1/nplot LET margin = 0.1 SET WINDOW -margin,1 + margin,-margin,1 + margin PLOT LINES: 0,0;1,1 ! draw diagonal line y = x PLOT LINES: 0,1;0,0;1,0 ! draw axes PLOT ! lift pen SET COLOR "red" LET x = 0 FOR i = 0 to nplot LET y = f(x,r,iterate) PLOT x,y; LET x = x + delta NEXT i END SUB SUB trajectory(x,r,iterate) DECLARE DEF f LET y0 = 0 LET x0 = x SET COLOR "blue" DO LET y = f(x,r,iterate) PLOT LINES: x0,y0; x0,y; y,y LET x0 = y LET y0 = y LET x = y LOOP until key input GET KEY k END SUB DEF f(x,r,iterate) ! f defined by recursive procedure IF iterate > 1 then LET y = f(x,r,iterate - 1) LET f = 4*r*y*(1 - y) ELSE LET f = 4*r*x*(1 - x) END IF END DEF