' ' ***************************************************************** ' ' 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 4: NPHASE.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 = 30: ym = 60: tm = 15# VIEW (180, 17)-(595, 330), 0, 14 WINDOW (-xm, -ym)-(xm, ym) LINE (-xm, 0)-(xm, 0), 11: LINE (0, -ym)-(0, ym), 11 LOCATE 13, 76: PRINT xm: LOCATE 1, 48: PRINT ym LOCATE 15, 1: PRINT "xi" LOCATE 23, 2: PRINT "Time" REM ****** Step-by-step method ****** LOCATE 13, 2: INPUT "r"; r t = 0#: xc(1) = 5#: xc(2) = 5#: xc(3) = 5# h = .003# DO GOSUB Runge t = t + h PSET (xc(1), xc(3)), 14 LOCATE 23, 6: PRINT CSNG(t) LOOP UNTIL ABS(t - tm) < h / 2 LOCATE 16, 1 FOR i = 1 TO n: PRINT CSNG(xc(i)): NEXT END REM ****** Subroutines ****** Equations: f(1) = 10# * (x(2) - x(1)) f(2) = -x(1) * x(3) + r * x(1) - x(2) f(3) = x(1) * x(2) - 8# * x(3) / 3# 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