A quick look at XPP

XPP is a software program designed to solve systems of differential equations. Up to 300 ODEs can be solved at one time. We will mainly consider systems with one and two dimensions. Here we will concentrate on autonomous systems with 1 variable. We will find fixed points, learn how to change numerical options, parameters, and initial data. We will also learn how to create hard copy. You can either run this little exercise (i) from within Netscape (if you have set things up correctly); (ii) from a terminal reading along; or (iii) with the hardcopy version of this.
If Netscape is hard to read, you can change the font under the Options, General Preferences, Fonts menu. Change to size 14 or 18 (if you are like me!)

The basic unit for XPP is a file called an ode file that tells XPP the parameter and variable names and other named things. These files are editable ascii files. Use your favorite editor! For class, however, I will give you most of the files so you won't have to learn an editor.

We will look at the differential equation:

dx/dt = f(x,t)

where f(x,t) is a continuous scalar function of 2 variables. We want to be able to put initial conditions in with a mouse and XPP prvents this if one of the axes is time, so we will study a two-dimensional system that is identical to the above equation:

ds/dt = 1
dx/dt = f(x,s)

Now s is a time-like variable whose solution is s = t+C , a shifted version of t. The ODE file for this is

# a generic first order equation with parameters 
param a,b,c,d
@ xp=s,yp=x,xlo=-5,xhi=20,ylo=-2,yhi=2
The first line is a comment (all comments start with # ). A function of x and t is defined. Some parameter names are given and since they are not set to any value assume the value of 0. The differential equations are then given. The line beginning with @ tells XPP some things about plotting etc. The last line tells XPP that this is it -- ignore everything below. If you are running this from within Netscape, click on the equations above and XPP should load up. Netscape generates a bunch of stuff that you can click OK on to dispose of. If you are running this externally from Netscape, then you have to start XPP from the command line. You should first copy the file to your directory. Type:
cp ~phase/class/first.ode .
Don't forget the dot. Now type
~phase/xpp first.ode

If all went well, you should have a window for XPP as well as a bunch of little iconified windows. If you get a message:

* (r)ead or (c)reate  
then you haven't gotten the file first.ode in your directory. Type
ls first.ode
to check if it is there. If not, try to get it again. Or just copy the file into your editor and save it as first.ode.
The main window shows x along the vertical axis and s which is just t along the horizontal. Zero axes are drawn.

To Exit XPP, click on (File) (Quit) and answer (Yes). To turn off the *%#!!$$ Bell, click on (File) (Bell off).

Now the fun begins. The first equation is the logistic equation:

dx/dt = x(1-x)

XPP lets you use keyboard of mouse shortcuts. Click on (Initialconds) (Mouse) and then click the mouse somewhere in the upper right quadrant. A trajectory will be drawn. Do it again several times in different locations. If you click below x=0 an OUT OF BOUNDS error will be generated since x goes beyond a limit that you can set. XPP forgets trajectories when new ones are created. To keep them on the screen click on (Graphics) (Freeze) (Freeze) and accept the defaults by clicking (OK). Now when you reintegrate the equations, the old curve will be saved along with the new one. Up to 10 trajectories can be frozen. Click on (Graphics) (Freeze) (Remove all) to get rid of the frozen curves. Freeze 3 or 4 trajectories using different initial conditions. Now click on (Dir. field/Flow) (Direct Field) and accept 10 for the grid. A field of tangents is drawn. Now save the whole thing in a postscript file by choosing (Graphics) (Postscript) and choose a file name. The default is first.ode.ps .

NOTE If you are running from within Netscape, do not accept the default. Instead backspace over the name and type whatever you want to call it -- otherwise it will not be put in your directory.

You can now print it out if you want.

Looking at the values

Click anywhere in the graphics window and hold down the mouse as you move it. The bottom of the window tells you the x-y coordinates. A better way to see the values of the variables is the Data Browser. Click on the iconified window labeled Data. This brings up a window that has columns of number corresponding to the values of the variable as different times. Click on the top bar of the Data Viewr and then use the mouse or the arrow keys to scroll through the numbers. Click on the button labeled (End) to go to the end. If the solution went to some asymptotic limit, this will be it and will be a fixed point. Click on (Home) to get the starting point. Click on the main XPP graphics window when you are finished looking at the numerical values.

Changing the numerics

If you have frozen a bunch of graphs, get rid of them now with the (Graphics) (Freeze) (Remove all) sequence. Choose (Initial conds) (New) and make s=0 and x=.01 and you will get a nice trajectory. Another way to change the initial conditions is to click on the iconified window labeled IC and change the numbers in the windows corresponding to the two variables. Click (OK) to accept the changes. Freeze the solution with the (Graphics) (Freeze) (Freeze), but this time change the color to 1 before clicking (Ok). Now click on (nUmerics) and a new menu appears. Change (Dt) by clicking on it and changing it from 0.05 to 2.0. Click on (Escape) and click (Initialconds) (Go) to reintegrate. Notice that the trajectory is pretty good. Freeze this in color 2. Now click on (nUmerics) again and change the (Method) from the default Runge-Kutta to the (Modified Euler) which is Heun's method. Click (Escape) to the main menu and click (Initialconds) (Go) to get another trajectory. This one is not so good. Freeze it in color 3. Finally change the method of integration to Euler by clicking (nUmerics) (Method) (Euler) and (Escape) to the main menu and reintegrate. It really sucks -- note the little zig-zags.

Numerical chaos

You can skip this and come back later. For some real fun enter the numerics menu and change the total amount of time (Total) to 400. Change (Dt) to 3. Change (Bounds) to 1000. (Escape) to the main menu. Click (Window) (Window) and make Xhi=400. and click (Ok) to make the big window. Solve the equations by clicking (Initialconds) (Go). This is a chaotic time series. Now change the window back by clicking (Window) (Window) and change Xhi to 20. Go back to the numerics menu and change (Total) to 20.

Change the Method back to (Runge-Kutta) and Dt back to 0.05 from the numerics menu. Get rid of any frozen curves.

Changing the equation

Click on (File) (Edit) (Functions). You should get a window with F(x,t) in it. Delete what's in there and replace it with
Click on (Ok). Draw the direction fields for this model. (First erase the screen with (Erase). Use the (Initialconds) (Mouse) option to choose a bunch of initial conditions. What are the fixed points? Which are stable? Do all trajectories end up at fixed points?


Sketch trajectories and direction fields for the following equations: For the equation:

dx/dt = -x + exp(-x)

draw the direction fields and solve numerically. By looking at the asymptotic limit for large t estimate the fixed point.

Here is a really wierd equation to fool with:

dx/dt = x*sin(1/x)

Look at several trajectories. Draw direction fields. How many fixed points do you find? Now use the (Window) (Window) command of XPP to change (Yhi) to 0.1 and (Ylo) to -0.1. Draw more trajectories in this window and the direction fields. Did you find more fixed points? Can you compute them analytically? Window it so that the (Yhi) is 0.01 and (Ylo) is -0.01. Try to compute a trajectory. Whoa -- this doesn't look right does it? Why is it failing? Try changing (Dt) in the (nUmerics) menu to something smaller (say 0.01). Now integrate a bunch of trajectories. It looks like everything is a fixed point!

Take me to the next stage -- two-d linear systems