DEFDBL A-Z 'Use double precision DIM a(12) 'Array of coefficients RANDOMIZE TIMER 'Reseed random numbers SCREEN 12 'Assume VGA graphics n% = 0 WHILE INKEY\$ = "" 'Loop until key is pressed IF n% = 0 THEN CALL setparams(x, y) CALL advancexy(x, y, n%) 'Advance the solution CALL display(x, y, n%) 'Display the results CALL testsoln(x, y, n%) 'Test the solution WEND END SUB advancexy (x, y, n%) SHARED a() xnew = a(1) + x * (a(2) + a(3) * x + a(4) * y) + y * (a(5) + a(6) * y) y = a(7) + x * (a(8) + a(9) * x + a(10) * y) + y * (a(11) + a(12) * y) x = xnew n% = n% + 1 END SUB SUB display (x, y, n%) STATIC xmin, xmax, ymin, ymax, w%, h% SELECT CASE n% CASE 1 'Initialize limits xmin = 1000: ymin = xmin: xmax = -xmin: ymax = -ymin CASE 2 TO 99 'Skip these CASE 100 TO 999 'Update limits IF x < xmin THEN xmin = x IF x > xmax THEN xmax = x IF y < ymin THEN ymin = y IF y > ymax THEN ymax = y CASE 1000 'Clear the screen CLS IF CSNG(xmax) = CSNG(xmin) THEN xmax = xmin + 1 IF CSNG(ymax) = CSNG(ymin) THEN ymax = ymin + 1 dx = (xmax - xmin) / 10: xmin = xmin - dx: xmax = xmax + dx dy = (ymax - ymin) / 10: ymin = ymin - dy: ymax = ymax + dy w% = 640 / (xmax - xmin): h% = 480 / (ymin - ymax) CASE ELSE 'Plot data xp% = w% * (x - xmin) yp% = h% * (y - ymax) PSET (xp%, yp%) 'Illuminate screen pixel END SELECT END SUB SUB lyapunov (x, y, n%, l) STATIC xe, ye, lsum IF n% = 1 THEN lsum = 0: xe = .000001#: ye = 0 xsave = x: ysave = y: x = xe: y = ye CALL advancexy(x, y, n% - 1) 'Reiterate equations xd = x - xsave: dy = y - ysave: d2 = dx * dx + dy * dy df = 100000000000# * d2: rs = 1# / SQR(df) xe = xsave + rs * (x - xsave): x = xsave ye = ysave + rs * (y - ysave): y = ysave lsum = lsum + LOG(df): l = .721347 * lsum / n% END SUB SUB setparams (x, y) SHARED a() x = 0: y = 0 FOR i% = 1 TO 12: a(i%) = (INT(25 * RND) - 12) / 10#: NEXT i% END SUB SUB testsoln (x, y, n%) nmax% = 10000 'Bailout value CALL lyapunov(x, y, n%, l) 'Get Lyapunov exponent (l) IF n% = nmax% THEN n% = 0 'Bailout value reached IF n% > 100 AND l < .005 THEN n% = 0 'Solution is not chaotic IF ABS(x) + ABS(y) > 1000000# THEN n% = 0 'Solution is unbounded END SUB