A quick look at XPP/WinPP

XPP/WinPP 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:

dy/dt = f(y,t)

where f(y,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
dy/dt = f(y,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 
f(y,t)=y*(1-y)
param a,b,c,d
ds/dt=1
dy/dt=f(y,s)
@ xp=s,yp=y,xlo=-5,xhi=20,ylo=-2,yhi=2,total=25
done
The first line is a comment (all comments start with # ). A function of y 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 you have the Windows version, download the file to your PC and then click on the WinPP icon. Then use the directory gadget to load in the ODE. It is useful to make a seperate directory for all your files.

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

(r)un (c)d (l)ist 
then you haven't gotten the file first.ode in your directory. Type Ctrl C to get out and make sure you have the program.
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 y along the vertical axis and s which is just t along the horizontal. Zero axes are drawn.

NOTE
To Exit XPP, click on (File) (Quit) and answer (Yes). In Windows type Ctrl-X or File Exit. To turn off the *%#!!$$ Bell, click on (File) (Bell off). (Not available in Windows).


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

dy/dt = y(1-y)

XPP lets you use keyboard or mouse shortcuts. Click on (Initialconds) (Mouse) and then click the mouse somewhere in the upper right quadrant. A trajectory will be drawn. (In Windows click on Run Mouse). Do it again several times in different locations. Better yet choose Mice from the options and just keep clicking away. Type ESC to exit this mode or click on STOP in Windows. If you click below y=0 an OUT OF BOUNDS error will be generated since y 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) (Autofreeze). In Windows Click on Graphics Keep Curve and check Autofreeze. Now when you reintegrate the equations, the old curve will be saved along with the new one. Up to 20 trajectories can be frozen. Click on (Graphics) (Freeze) (Remove all) to get rid of the frozen curves. (Graphics Keep curve Delete all in Windows). Freeze 3 or 4 trajectories using different initial conditions. Now click on (Dir. field/Flow) (Scaled Direct Field) and accept 10 for the grid. (Use Phaseplane Direction field in Windows). A field of tangents is drawn. Now save the whole thing in a postscript file by choosing (Graphics) (Postscript) and choose a file name. (In Windows, click on File Print) 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 (Browser, in Windows). 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. Turn off the Auto-freeze. Choose (Initial conds) (New) and make s=0 and y=.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. Use this way for Windows! Freeze the solution with the (Graphics) (Freeze) (Freeze), but this time change the color to 1 before clicking (Ok). (In Win95, click on Graphics Keep curve. Click on Add New to the dialog box and choose Red as the color; click 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). In Win95, choose Numerics Int.par to get a dialog box and change Delta-T; then click OK.) 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) (RHS). You should get a window with the odes in it. Delete the second one and replace it with
y*(1-y^2)
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?

Homework

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

dy/dt = -y + exp(-y)

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

Try problems 4,5,6 (page 15) in your book. Make sure you make the window the same as you are told in the book. (Use the Window Window command. To run a range of initial conditions (eg for problem 5), click on Initconds Range and fill in the dialog as follows:

Then click on OK.

Here is a really weird equation to fool with:

dy/dt = y*sin(1/y)

Look at several trajectories. Draw direction fields. How many equilibria 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!

Notes to Win95 Users