!GRAPHICAL ITERATION OF LOGISTIC EQUATION

! Xnew = a*Xold*(1-Xold)

SET MODE "graphics"

SET WINDOW -0.4,1.2,-.1,1.2

PRINT "THE LOGISTIC EQUATION IS: Xn+1 = a*Xn*(1-Xn)"

INPUT PROMPT "ENTER THE PARAMETER a (0 to 4): ":a

BOX LINES 0,1,0,1

SET TEXT JUSTIFY "center","top"

PLOT TEXT, AT 0,0 :"0"

PLOT TEXT, AT 1,0 :"1"

SET TEXT JUSTIFY "rigth","bottom"

PLOT TEXT, AT -.05,0 :"0"

PLOT TEXT, AT -.05,1 :"1"

PLOT TEXT, AT -.05,a/4 :STR\$(a/4)

!Plot the y=x diagonal

PLOT 0,0;1,1

PRINT "Then the fixed point (Xn+1 = Xn) is at X = 1- 1/a = ";1-1/a

PRINT "Click on the plot to select a seed x0"

!Plot the function y(x) = a*x*(1-x) in red

FOR x= 0 to 1 step 0.005

SET COLOR "RED"

LET y= a*x*(1-x)

PLOT x, y;

NEXT x

!Graphical iteration is done upon selection of seed x0 with mouse.

FOR j=0 to 10

DO

GET MOUSE x,y,s

IF s=2 THEN EXIT DO

SET CURSOR 5,60

SET COLOR "BLUE"

PRINT USING "x=#.####, y=#.####": x,y

LOOP

IF j=0 THEN SET COLOR "red"

IF j=1 THEN SET COLOR "brown"

IF j=2 THEN SET COLOR "cyan"

IF j=3 THEN SET COLOR "blue"

IF j=4 THEN SET COLOR "green"

IF j=5 THEN SET COLOR "yellow"

IF j=6 THEN SET COLOR "magenta"

IF j>6 THEN SET COLOR "black"

PLOT

GET POINT x0,y0

PRINT "x0 is: ";x0

SET TEXT JUSTIFY "center","top"

PLOT TEXT, AT x0,0 :"x0"

PLOT x0,0;

LET x=x0

FOR i=1 to 30

LET x1= a*x0*(1-x0)

PLOT x0,x1;x1,x1;

PAUSE 0.5

LET x0=x1

NEXT i

NEXT j

END