' ' ***************************************************************** ' ' 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 1: 1XT.BAS ' ' REM ****** Setting up graphics ****** CLS : SCREEN 9: PAINT (1, 1), 9 xm = 3: tm = 5 VIEW (180, 17)-(595, 330), 0, 13 WINDOW (0, -xm)-(tm, xm) LINE (0, 0)-(tm, 0), 11: LINE (0, -xm)-(0, xm), 11 LOCATE 12, 76: PRINT tm: LOCATE 1, 21: PRINT xm REM ****** Function f(x,t) ****** DEF fnf (x, t) = (1 + t) * x + 1 - 3 * t + t ^ 2 REM ****** Direction field ****** p = 25 FOR x = xm TO -xm STEP -2 * xm / p FOR t = 0 TO tm STEP tm / p x1 = fnf(x, t) / xm: t1 = 2 / tm s = p * SQR(x1 ^ 2 + t1 ^ 2) x2 = fnf(x, t) / s: t2 = 1 / s LINE (t, x)-(t + t2, x + x2), 9 CIRCLE (t + t2, x + x2), .003 * tm, 9 NEXT t NEXT x REM ****** Step-by-step method ****** DO t = 0: LOCATE 13, 1: INPUT "x0"; x h = .01 DO GOSUB Runge t = t + h PSET (t, x), 14 LOOP UNTIL ABS(t - tm) < h / 2 OR ABS(x) > xm LOCATE 19, 1: PRINT "t="; t LOCATE 20, 1: PRINT "x="; x LOOP REM ****** Subroutines ****** Euler: c1 = h * fnf(x, t) x = x + c1 RETURN ImpEuler: c1 = h * fnf(x, t) c2 = h * fnf(x + c1, t + h) x = x + (c1 + c2) / 2 RETURN Runge: c1 = h * fnf(x, t) c2 = h * fnf(x + c1 / 2, t + h / 2) c3 = h * fnf(x + c2 / 2, t + h / 2) c4 = h * fnf(x + c3, t + h) x = x + (c1 + 2 * c2 + 2 * c3 + c4) / 6 RETURN