' ' ***************************************************************** ' ' FROM CALCULUS TO CHAOS ' ' An Introduction to Dynamics ' ' ' by ' ' David Acheson ' ' ****************************************************************** ' ' The program which follows is part of the above book, ' published in 1997 by Oxford University Press. ' ISBN 0-19-850077-7 (paperback) ' ' ' Copyright ¸ David Acheson 1997 ' ' ' ' ' Program 5: NXT.BAS ' ' DEFDBL A-H, K-M, O-Z: DEFINT I-J, N n = 3: OPTION BASE 1 DIM x(n), xc(n), f(n), c1(n), c2(n), c3(n), c4(n) REM ****** Setting up graphics ****** CLS : SCREEN 9: PAINT (1, 1), 9 xm = 4: tm = 50# VIEW (20, 30)-(575, 240), 0, 13 WINDOW (0, -xm)-(tm, xm) LINE (0, 0)-(tm, 0), 11: LINE (0, -xm)-(0, xm), 11 FOR d = .1 TO 1 STEP .1 LINE (d * tm, 0)-(d * tm, xm / 40), 11 NEXT LOCATE 2, 1: PRINT xm: LOCATE 10, 74: PRINT tm LOCATE 19, 43: PRINT "xi" LOCATE 22, 2: PRINT "Time" REM ****** Step-by-step method ****** DO k = .05#: w = 1#: a = 7.5# LOCATE 19, 1 INPUT "x1,x2,h,col"; xc(1), xc(2), h, col t = 0#: xc(3) = 0# DO GOSUB Runge t = t + h PSET (t, xc(1)), col LOOP UNTIL ABS(t - tm) < h / 2 OR INKEY$ = "q" LOCATE 22, 6: PRINT t FOR i = 1 TO n LOCATE 18 + i, 46: PRINT ; xc(i) NEXT LOOP REM ****** Subroutines ****** Equations: f(1) = x(2) f(2) = -k * x(2) - x(1) ^ 3# + a * COS(w * x(3)) f(3) = 1# RETURN Runge: FOR i = 1 TO n: x(i) = xc(i): NEXT GOSUB Equations FOR i = 1 TO n: c1(i) = h * f(i): NEXT FOR i = 1 TO n: x(i) = xc(i) + c1(i) / 2#: NEXT GOSUB Equations FOR i = 1 TO n: c2(i) = h * f(i): NEXT FOR i = 1 TO n: x(i) = xc(i) + c2(i) / 2#: NEXT GOSUB Equations FOR i = 1 TO n: c3(i) = h * f(i): NEXT FOR i = 1 TO n: x(i) = xc(i) + c3(i): NEXT GOSUB Equations FOR i = 1 TO n: c4(i) = h * f(i): NEXT FOR i = 1 TO n xc(i) = xc(i) + (c1(i) + 2# * c2(i) + 2# * c3(i) + c4(i)) / 6# NEXT RETURN