'Program EXAMINEZ.BAS makes a state-space plot for PARAMSZ.DAT \$error all on defext a-z screen 12 call invertcolors n&=100 s=1.11## scale=1 eps=scale/460 xo=1##/3## randomize timer dim x(n&), dxdt(n&), xnew(n&) open"initcond.100" for input as #1 for i&=1 to n& 'random initial conditions input#1,x(i&) next i& close #1 q\$="C" while q\$<>chr\$(27) if q\$="B" then 'make bmp file call scn2bmp("EXAMINEZ.BMP") end if if q\$=chr\$(0,72) then 'increase s s=s+.001## q\$="C" end if if q\$=chr\$(0,80) then 'decrease s s=s-0.001## q\$="C" end if if q\$="P" then 'cycle Poincare section p&=(p&+1) mod 3 q\$="C" end if if q\$="C" then 'clear screen cls t&=0 locate 1,13: print"N =";n&; locate 2,13: print"S =";s; if p&>0 then print" P =";p&; line(90,0)-(550,460),,b scale\$=trim\$(str\$(scale)) locate 1,12-len(scale\$): print scale\$; locate 15,8: print"X(2)"; locate 29,11: print"0"; locate 30,12: print"0"; locate 30,39: print"X(1)"; locate 30,70-len(scale\$): print scale\$; end if RK4 x(), dxdt(), n&, .05, xnew() incr t& if (t& mod 1000)=0 then locate 3,13: print"T =";0.05##*t&; if p&=0 then c&=15 if p&>0 then if (xnew(3)-xo)*(x(3)-xo)<0 then fraction=abs((x(3)-xo)/(xnew(3)-x(3))) c&=15 for i&=1 to n& x(i&)=x(i&)+fraction*(xnew(i&)-x(i&)) next i& else c&=0 end if end if if p&>1 and c&>0 then if abs(x(n&/2+2)-xo)-scale and c&>0 then xp=90+459*x(1)/scale yp=459-459*x(2)/scale pset(xp,yp),c& end if for i&=1 to n&: x(i&)=xnew(i&): next i& q\$="": if timer<>t0 then q\$=ucase\$(inkey\$): t0=timer wend end SUB invertcolors () 'Sets the RGB palette to iverted gray scale in 16-color VGA screen modes FOR pal& = 0 TO 15 PALETTE pal&, pal& c& = 63-INT(4.2 * pal&) OUT &h3C8, pal& OUT &h3C9, c& OUT &h3C9, c& OUT &h3C9, c& NEXT pal& END SUB SUB scn2bmp (filename\$) 'Captures the screen to a file filename\$ in bitmaped (BMP) format 'Palette correct in EGA and VGA color modes 7 - 12 only WINDOW SCREEN (0, 0)-(1, 1) 'Get width and height of screen w& = 1 + PMAP(1, 0) h& = 1 + PMAP(1, 1) WINDOW x1& = 0: y1& = 0: x2& = w&-1: y2& = h&-1 'Corners of image x2& = x1& + 16 * CEIL((x2& - x1&) \ 16 + .01) - 1 SOUND 1000, .3 SOUND 750, .3 sw& = 1 + x2& - x1& 'Width of image in pixels sh& = 1 + y2& - y1& 'Height of image in pixels sf& = sw& * sh& \ 2 'Bytes in image f& = FREEFILE OPEN filename\$ FOR OUTPUT AS f& PRINT #f&, MKWRD\$(&H4D42); 'ASCII "BM" PRINT #f&, MKL\$(sf& + 118); 'Size of file in bytes PRINT #f&, MKDWD\$(0); 'Must be zero PRINT #f&, MKWRD\$(&h76)+MKWRD\$(0)+MKWRD\$(&H28)+MKWRD\$(0); PRINT #f&, MKL\$(sw&); 'Screen width PRINT #f&, MKL\$(sh&); 'Screen height PRINT #f&, MKWRD\$(1)+MKWRD\$(4)+MKDWD\$(0); PRINT #f&, MKL\$(sf&); 'Size of image in bytes PRINT #f&, MKDWD\$(0)+MKDWD\$(0)+MKDWD\$(0)+MKDWD\$(0); FOR i& = 0 TO 15 'Palette RGB values (0 - 15) out &h3C7,i& red?=4.047619*inp(&h3c9) grn?=4.047619*inp(&h3c9) blu?=4.047619*inp(&h3c9) PRINT #f&, MKBYT\$(blu?);MKBYT\$(grn?);MKBYT\$(red?);MKBYT\$(0); NEXT i& a\$ = SPACE\$(sw& \ 2) FOR y& = y2& TO y1& STEP -1 x& = x1& WHILE x& < x2& a? = POINT(x&, y&) SHIFT LEFT a?, 4 INCR x& a? = a? OR POINT(x&, y&) INCR x& MID\$(a\$, (x& - x1&) \ 2, 1) = MKBYT\$(a?) WEND PRINT #f&, a\$; NEXT y& CLOSE f& SOUND 800, .3 SOUND 600, .3 END SUB SUB DERIVS (x(), dxdt(), n&) 'Returns the time derivatives dxdt(i&) of x(i&) SHARED s FOR i&=1 TO n& i1&=1+(i&-3+n&) MOD n& i3&=1+i& MOD n& dxdt(i&)=x(i&)*(1##-s*x(i1&)-x(i&)-s*x(i3&)) NEXT i& END SUB SUB RK4 (X(), DXDT(), N&, H, XNEW()) 'Fourth-order Runge-Kutta integrator DIM XT(N&), DXT(N&), DXM(N&) HH = H * .5## H6 = H / 6## CALL DERIVS(X(), DXDT(), N&) FOR I& = 1 TO N& XT(I&) = X(I&) + HH * DXDT(I&) NEXT I& CALL DERIVS(XT(), DXT(), N&) FOR I& = 1 TO N& XT(I&) = X(I&) + HH * DXT(I&) NEXT I& CALL DERIVS(XT(), DXM(), N&) FOR I& = 1 TO N& XT(I&) = X(I&) + H * DXM(I&) DXM(I&) = DXT(I&) + DXM(I&) NEXT I& CALL DERIVS(XT(), DXT(), N&) FOR I& = 1 TO N& XNEW(I&) = X(I&) + H6 * (DXDT(I&) + DXT(I&) + 2## * DXM(I&)) NEXT I& ERASE DXM, DXT, XT END SUB