'Program lvmodel.bas solves Multispecies Lotka-Volterra system without evolution #DEBUG ERROR OFF DEFEXT a-z GLOBAL a() AS EXT GLOBAL s AS EXT DECLARE SUB DERIVS (x(), dxdt(), n&) DECLARE SUB RK4 (x(), dxdt(), n&, h, xnew()) FUNCTION PBMAIN CONSOLE NAME"Lotka-Volterra Model" CONSOLE SCREEN 25,80 CLS: CURSOR OFF n&=10 'Number of variables h=0.05 'Step size dr=1e-12 'Perturbation for LE calculation s=1.30## 'Bifurcation parameter dr2=dr*dr DIM x(n&), xnew(n&), dxdt(n&), xe(n&), xenew(n&), dx(n&), a(m&) FOR i&=1 TO n&: x(i&)=RND: xe(i&)=x(i&)+SQR(dr2/n&): NEXT i& ltot=0: t&=0 WHILE INKEY\$="" RK4 x(), dxdt(), n&, h, xnew() RK4 xe(), dxdt(), n&, h, xenew() rs2=0 FOR i&=1 TO n& dx(i&)=xenew(i&)-xnew(i&) rs2=rs2+dx(i&)*dx(i&) NEXT i& rs=SQR(rs2/dr2) 'Calculate largest Lyapunov exponent and sum of exponents FOR i&=1 TO n&: xe(i&)=xnew(i&)+dx(i&)/rs: NEXT i& INCR t& IF t&>10000 THEN ltot=ltot+LOG(rs) le=ltot/(h*(t&-10000)) END IF bm=0 FOR i&=1 TO n& jold&=SCREENX*x(i&) x(i&)=xnew(i&) IF n&>SCREENY THEN ITERATE j&=SCREENX*x(i&) IF j&=jold& THEN ITERATE LOCATE i&,1: PRINT SPACE\$(SCREENX); LOCATE i&,1: PRINT STRING\$(j&, 219); NEXT i& IF (t& MOD 9999)=0 THEN LOCATE 25,1: PRINT "LE =";ROUND(le,8); END IF WEND CLOSE END FUNCTION SUB DERIVS (x(), dxdt(), n&) 'Returns the time derivatives dxdt(i&) of x(i&) 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