DEFDBL a-z DECLARE FUNCTION fy (x, y, z) DECLARE FUNCTION fz (x, y, z) ' ' Sample program to solve the system of two coupled ' differential equations ' ' y' = fy(x,y,z) ' z' = fz(x,y,z) ' ' using the simultaneous midpoint method ' ' The exact form of the right hand sides are placed ' in FUNCTION FY and FUNCTION FZ of this program PRINT "" PRINT "P. Hellings: Astrophysics with a PC : SOME NUMERICAL METHODS" PRINT "-------------------------------" ' Adapted by Kiyoshi Kawabata from the program of Chapter 1 COLOR 14 PRINT "Key in x(0)=0, y(0)=1, z(0)=0, Stepsize=0.05, " &_ "Number of iteration =10" PRINT "to reproduce the tabular values on p.15" COLOR 15 INPUT "Initial condition x(0) = "; x INPUT "Initial condition y(0) = "; y INPUT "Initial condition z(0) = "; z INPUT "Stepsize dx = "; dx INPUT "Number of iteration to be computed = "; n% PRINT " i x y z" i%=0 PRINT USING "#### #####.##### #####.###### #####.######";_ i%; x; y; z FOR i% = 1 TO n% ' compute first half of new iteration x12 = x + .5 * dx y12 = y + .5 * dx * fy(x, y, z) z12 = z + .5 * dx * fz(x, y, z) ' compute full iteration with slope at half the step x1 = x + dx y1 = y + dx * fy(x12, y12, z12) z1 = z + dx * fz(x12, y12, z12) ' display new iteration PRINT USING "#### #####.##### #####.###### #####.######";_ i%; x1; y1; z1 ' prepare for next iteration x = x1 y = y1 z = z1 NEXT i% COLOR 14 PRINT "Press any key to terminate the job!!!" DO LOOP WHILE INKEY$ = "" END FUNCTION fy(x, y, z) ' ' contains the right hand side of the differential equation ' y' = fy(x,y,z) ' fy = -2 * z END FUNCTION FUNCTION fz(x, y, z) ' ' contains the right hand side of the differential equation ' z' = fz(x,y,z) ' fz = y - (SIN(x)) ^ 2 END FUNCTION