'The Standard Logistics Difference Equation
'This program exercises the difference equation x = rx(1 - x) for different
'values of r [r was renamed c in the applet]. For r < 2.1 it produces the
'familiar sigmoid curve used to represent the growth of populations, market
'demand and a myriad other things. For 2.1 < r < 2.9 the curve climbs to
'a maximum then follows a dying oscillation which eventually settles to a
'constant value. For 2.9 < r < 3.4 the curve climbs as usual but settles
'down to a regular oscillation. For 3.4 < r < 3.6 the oscillation
'becomes increasingly complex, at one point adopting a kind of waltz rhythm.
'From 3.7 < r < 4 regular oscillations give way to chaotic behaviour.
'For r > 4 this becomes so extreme that the 'population' soon hits zero
'and thus destroys itself.
'StdLog.BAS
screen 9,3 : color 7,1 : window (-50,-200) - (+350,+200)
xy = 4/5 'aspect ratio of IBM PC CGA screen
bias1 = 42
bias2 = -150
s = 4
gosub FrameSub
a:
locate 17,40 : input"r = ",r$ : if r$="" then end
LOCATE 18,40 : input"x = ",x$ : if x$ = "" then x$ = ".001"
gosub FrameSub
r = val(r$)
OldX = val(x$)
for k = 0 to 350 step s 'for 350/s generations...
NewX = r * OldX * (1 - OldX) 'update the value of x
if OldX > 0 and NewX > 0 then 'If population not died out..
y = (NewX - OldX) / OldX 'update the value of x-dashed
else
NewX = 0 'population has all died out
end if
xNew = 150 * NewX 'new x-pixel co-ordinate
yNew = 50 * y 'new y-pixel co-ordinate
if k > 0 then
pset((k - s) * xy, xOld + bias1), 7 'Draw time graph's
line-( k * xy, xNew + bias1), 7 'line increment.
pset(yOld * xy, xOld + bias2), 7 'Draw phase-graph's
line-(yNew * xy, xNew + bias2), 7 'line increment.
end if
OldX = NewX 'set up the value of OldX ready for next pass
xOld = xNew 'set up new x-pixel as next pass's old x-pixel
yOld = yNew 'set up new y-pixel as next pass's old y-pixel
next
goto a 'go back to accept another value of r
FrameSub:
cls
locate 11,31 : print"TIME SERIES DIAGRAM"
locate 1,10 : print "x"
locate 10,68 : print"t"
LOCATE 23,12 : PRINT"PHASE-SPACE DIAGRAM"
LOCATE 22,36 : print"dx"
LOCATE 23,36 : print"dt"
locate 13,10 : print"x"
line(-40 * xy, bias1)-(+350 * xy, bias1)
line(-40 * xy, bias2)-(+150 * xy, bias2)
line(0, bias2)-(0, bias2 + 150)
line(0, bias1)-(0, bias1 + 150)
locate 15,38 : print "Exercise formula: x = rx(1 - x)"
locate 17,40 : print "r = ";r$
locate 18,40 : print "x = ";x$
locate 4.1
return
'November 1997 Robert John Morton