(****************************************************) User Manual for the program set RKStrob (****************************************************) (* Mathematical formulas in this instruction are typed in TeX notation *) 1.Purpose and possibilities. This is a collection of TurboPascal (>=5.0) for DOS sources (units and example programs) designed to observe various characteristics of dynamical systems. To investigate numericaly your problem make appropriate changes in supplied examples. The simplest way is to type your formulae for vector fields and initial conditions. More advanced work is to modify the procedure StrobHandler. Principal possibilities: -Numerical integration of initial problem for an ordinary differential equation $$ dx/dt=f(x,t), x(0)=x_0, x=(x_1,x_2,..., x_N) $$ (by 5-order Runge-Kutta-Fehlberg method with varying step). -Presentation of results of integration in different forms: a) graphic or digital, in file or screen; in file prepared for LaTex translation to graphic form, etc. b) selection of resulting data: integral curve(s) in various sections of a phase space, e.g. in various variables; or Poincare section. c) new procedures for handling points of an integral curve may be easily added. (*********************************************) (*********************************************) 2. Examples. Examples illustrate how to use the procedures. Reading of this instruction should be parallel to your work with example programs. Each example is a source TurboPascal (>=5.0) file, and may be compiled from the TurboPascal integrated development environment. Ex.1: File <> contains program EXAMPLE. It illustrates numerical integration of the system $$ dx/dt=y, dy/dt=-x $$ with output of results to the screen in digital form. Ex.2: File <> contains program EXAMP_GR. It illustrates numerical integration of the system $$ dx/dt=y-0.03x, dy/dt=-x $$ with output of results to the screen in graphical form: an integral curve on the phase plane is being drawn. Ex.3: File <> contains program EXAM_POI. It illustrates numerical integration of a model 4-dimensional authonomous system, known as Henon-Heyles system. It is a hamiltonian system with two degrees of freedoms and the Hamilton function $$ H= (p_1^2+p_2^2)/2 + (x_1^2+x_2^2)/2 +x_1^2 x_2 - x_2^3/3 $$ Output of results is done to the screen in graphical form: the Poincare section ($x_1=0$) for fixed value of energy $H$. Ex.4: File <> contains program EXAMP_TEX. It illustrates numerical integration of the Henon-Heyles system (see Ex.3) with output of results to the screen and to an ASCII file which contains a description of the picture in LaTeX format. This file is ready for immediate LaTeX processing. Find the file <> in the directory after runing the program EXAMP_TEX. (******************************************************) (******************************************************) 3. Specifications of units of the program set. A) Procedure for numerical integration is in the file <>. Its header: procedure RKF_STROB(N_VAR: integer; var Y:vectortype; RightHandSide: proctype; StrobHandler: tracer; Integration_Time: realtype); The parameters are: N_Var -- number of variables in a given system of ODE. (less then 15). Y -- vector of initial conditions for ODE RightHandSide -- vector field (it must be a procedure itself-- see item B) StrobHandler -- defines what to do with successive points on the integral curve (provides different output of integration results) (it must be a procedure -- item B) Integration_Time -- positive or negative real number; if negative then the integration goes backward. The table shows corresponding values of parametres in examples ____________________________________________________________________ N_VAR Y RightHandSide StrobHandler Integration_Time ____________________________________________________________________ Ex.1 2 (1;0) RHS PlainHandler 1000.0 ____________________________________________________________________ Ex.2 2 (1;0) RHS2 GraphHandler 100.0 ____________________________________________________________________ Ex.3 4 (*) HenonHeyles PoincareSectionHandler -1000.0 ____________________________________________________________________ Ex.4 4 (**) HenonHeyles PoincareSectionHandler2 (**) ____________________________________________________________________ Comments to the table: (*) in Ex.3 initial condition is $ x_1=x_3=0, p_2=0.25 $ and $p_1$ is calculated automatically to provide the value of energy $H=0.005$ (**) in Ex.4 there are 6 random initial conditions, so we have 6 curves on the Poincare section. For each curve time of integration is different (because near a separatrice the integration goes more slowly than apart of it). (******************************) B) procedures-parameters for the procedure RKF_STROB. RightHandSide: calculates components of a vector field $f$ for given values of the time $t$ and the phase space coordinates x[1],..,x[N_VAR]. Its type is proctype=procedure(t:realtype; var x,f:vectortype); StrobHandler: defines what to do with current point $x(t)$ on the integral curve; can manipulate with an auxiliary variable END_MARK. In the examples: Ex.1 : PlainHandler displays current values of coordinates; Ex.2 : GraphHandler puts a dot with current coordinates on the screen with some linear scaling; Ex.3 : PoincareSectionHandler: when a trajectory $x(t)$ crosses the Poincare section $x_1=0$ puts a dot with coordinates $(x_3(t),x_4(t)$) (linearly scaled) on the screen. E4 : PoincareSectionHandler2: when a trajectory $x(t)$ crosses the Poincare section $x_1=0$ puts a dot with coordinates $(x_3(t),x_4(t)$) (linearly scaled) on the screen and writes the coordinates to a file in a special format for LaTeX processing. Type of StrobHandles is tracer=procedure(var x:vectortype; var end_mark: word); (****************************************) C) Procedures for drawing on the screen. To have picture as a result of your program work you must have the standart Borland's files EGAVGA.BGI and GRAPH.TPU in the directory according to your TurboPascal system settings. Unit CURVE (file CURVE.PAS) refers to them. Procedures collected in CURVE provide placing and scaling for your pictire on the screen. They are: --Procedure IniPic(LeftDown,RightUp: Point2): gives scale parametres such that the point with coordinates LeftDown is strictly in the left lower corner of your screen and the point with coordinate RightUp is in the right upper corner of the screen; --Procedure ClosePic: Indicates when integration is done; after that you can admire the picture until you press any key and then the picture disappears forever -- till the next start of the program with the same initial data. -- Procedure PutDot(var here: Point2): rounds current scaled coordinates to integers and puts a dot with current color on the screen. --Procedure PutLine(var inipoint, endpoint: Point2): rounds current scaled coordinates of two points and draws the segment between these two points on the screen. --Procedure AssignColor: assigns the value of CurrentColor to the default color of all future objects of the screen, e.g. lines. For example, if you simply write CurrentColor:=LightGray then points will be coloured in LightGray, but lines will not. To make future lines coloured in LightGray, you have to add the instruction AssignColor. (***********************************************) D) Procedures for TeX files preparation. D1) Let us start with some preliminaries about drawing pictures in LaTeX. (For futher detailes see e.g. the textbook by S.M.L'vovsky). Each LaTex file is an ASCII file which must begin with a preamble, for example, \documentstyle[12pt]{article} \begin{document} and end with \end{document} To draw a picture in Latex you have to fill this file with special lines, set between \unitlength 1mm \begin{picture}(150.0000,200.0000) and \end{picture} Numbers in (,) denote horizontal and vertical size of the picture respective to the unit of length defined by the line "\unitlength ..." (you can use any TeX length description instead of "1mm"). Each graphical object has its reference point. For drawing an object whose reference point has coordinates (A,B) one has to write \put(A,B){ } The object can be e,g. a segment, a text or something else. For drawing a segment : \put( A, B){\line(C,D){E}} where $A,B,C,D,E$ are numbers. As a result you get slanting line having the slope defined by the angle $\alpha=\artan D/C$, and length E (respective to the unit of length). For example if $C=1, D=0$, you get a horizontal line, if $C=0, D=1$, the line is vertical. If $ E \ll 1 $ then you have just a point -- a very short line. To write text on your picture : \put (A,B) { } (TEXT may include formulae framed in $$.) One can use \multiput( A,B)(a,b){n}{ OBGECT} to draw a sequence of $n$ identical equidistant objects starting from the point $(A,B)$ with step $(a,b)$ i.e. at points $(A+k*a, B+k*b)$, $k=0,...,n$. (May be useful for drawing lattice on your picture). Procedures contained in Unit TEXPIC.PAS provide sufficient tools to draw a border of your picture, coordinate axes (with primes and corresponding values), and integral curve(s) (point by point). (****************) D2) Programe Exmp_tex creates the file <> with a picture described in LaTeX format. It uses procedures collected in file <> (see D3). Here we give comments to lines of the file <> concerning tex picture drawing. TexFileName:='exmp_tex.tex'; -- name of the output file. --------------------------------------------- PictureHeight:=200;{mm} PictureWidth:=150;{mm} -- height and width of the picture. --------------------------------------------- GlobalShiftX:=0; GlobalShiftY:=0; --------------------------------------------- NumPrecision:=4; {float point format 7:4} -- 4 sings after point in number on pictire axes. --------------------------------------------------------- Preamble(TexFileName); -- opens the file <> and writes its first part \documentstyle[12pt,preprint]{article} \newcommand{\PT}{\line(0,1){0.05}} \begin{document} %\large \unitlength1mm \begin{picture}(150.0000,200.0000) Text of this procedure is located in <> -------------------------------------------------------------- Frame; -- write to file <> lines for drawing the border (according to an assigned dimension) \put( 0.0000, 0.0000){\line(1,0){150.0000}} \put( 0.0000, 0.0000){\line(0,1){200.0000}} \put( 0.0000,200.0000){\line(1,0){150.0000}} \put(150.0000, 0.0000){\line(0,1){200.0000}} Text of this procedure is located in <> --------------------------------------------------------------- Axes (LeftDown.x,LeftDown.y,RightUp.x,RightUp.y,10,8,3); -- writes lines for drawing primes on the axes (in our example the axes coinside with segments of the border) \multiput(16.6667, 0.0000)(16.6667, 0.0000){8}{\line(0,1){2}} \multiput( 0.0000,18.1818)( 0.0000,18.1818){10}{\line(1,0){2}} \multiput(16.6667,200.0000)(16.6667, 0.0000){8}{\line(0,-1){2}} \multiput(150.0000,18.1818)( 0.0000,18.1818){10}{\line(-1,0){2}} and then sets coordinate values near the primes: \put( 6.6667, 2.8000){$-0.361$} \put(23.3333, 2.8000){$-0.222$} \put(40.0000, 2.8000){$-0.083$} \put( 2.8000,16.3818){$-0.409$} \put( 2.8000,34.5636){$-0.318$} \put( 2.8000,52.7455){$-0.227$} Meanings of the last three parameters: the 6th parameter is 8, as a result you get 8 primes on the vertical axis with step 16.6667 = (Rightup.y-LeftDown.y) /8; the 5th parameter is 10 resulting in 10 primes on the horizontal axis with step 18.1818 = (Rightup.x-LeftDown.x) /10. The last (7th parameter) 3 makes numeric values near each prime to have the floating point format with 3 digits after the point. Text of this procedure is located in <> ------------------------------------------------------------------- SetPictureScale(LeftDown,RightUp); -- provides rescaling such that the "physical" integration region (whose boundaries are determined by Rightup.x,Rightup.y,LeftDown.x,LeftDown.y) be mapped exactly to the whole picture region determined by PictureWidth and PictureHeight. Text of this procedure is located in <> -------------------------------------------------------------------- RKF_Strob(N_Var,X,HenonHeyles,PoincareSectionHandler2,TMax); -- integration with Poincare section selected; Note that PoincareSectionHandler2 calls the procedure OutputDot(pt); which, in its turn, uses PtTo(pt). It writes to the resulting file <> the following lines: \put(60.0000,126.7043){\PT} \put(50.1629,76.1026){\PT} \put(49.3483,126.5554){\PT} \put(54.4770,74.4038){\PT} and so on where the macrocommand \PT is defined in the preamble as \newcommand{\PT}{\line(0,1){0.05}} and means a very short line, just a point. These points consist the integral curve (each line in the file corresponds to one point on the pictire). ------------------------------------------------------- Postamble(TexFileName); --writes to the file <> the last part \end{picture} \end{document} and closes it. Text of this procedure is located in <> (*****************************) D3) Unit TexPic containes procedures procedure writenum(x: real); -- transforms a number x to string format (to write it to text file as a string). ------------------------------------------------- procedure oo(st: string); -- writes string with Carriage Return to the file. ---------------------------------------------------- procedure o(st: string); -- writes string without Carriage Return to the file. ---------------------------------------------------- procedure preamble(texfilename: string); procedure postamble; -- see item D2. ------------------------------------------------------ function put(x,y: real): boolean; -- checks if the point with current coordinates belongs to the admissible region of the phase spase, and if yes, transforms the scaled coordinates to line, e.g. \put(60.0000,126.7043) ---------------------------------------------------------- procedure SetPictureScale(var LeftDown,RightUp: Point2); -- see item D2 --------------------------------------------------------- procedure movto(var pt: Point2); and procedure linto(var pt: Point2); -- these procedures create lines with TeX command "\special". It performs an action which is not defined in standard TeX or LaTeX, but is provided by a TeX compiler as an extension of standard TeX possibilities. In our case the specials {em:moveto} and {em:lineto} from TeX package writen by Eberhard Mattes (EMTeX) are used. These EMTeX commands change a position of an internal pointer, which indicates some reference point on the graph. The command \special{em:moveto} does not do anything besides changing the pointer position, while \special{em:lineto} draws the line from old to new pointer position. The procedures movto(var pt: Point2) and linto(var pt: Point2) write corresponding lines to the file <>. E.g. \put(60.0000,126.7043){\special{em:moveto}} sets the pointer position to (60.0,126.7043); then \put(50.1629,76.1026){\special{em:lineto}} sets the pointer position to (50.1629,76.1026) and draws the line between (60.0,126.7043) and (50.1629,76.1026). ------------------------------------------------------------ The authors will appreciate your notes, comments and suggestions on this software. E-mail addresses: Sergey Sadov sadov@keldysh.ru Yuri Sadov yu@bibigon.msk.ru Margarita Kondrat'eva margo@physics.umanitoba.ca