Mathematical Modeling: laboratory exercise 2

Phase portraits. Population (Lotka-Volterra) models.


Exercise 1

Plot the phase portrait for
d2x/dt2x - ω2x = 0
Set y=dx/dt, thus we have the system of equations
dx/dt=y
dy/dt=ω2x

Fixed Point: (i) x=0, y=0

Phase curves are given by
ω2 x2/2-y2/2 = C
[explain why.]

Let us first plot the function f(x,y)=ω2 x2/2-y2/2.
Then make a contour plot of this function which is equivalent to plotting the the phase curves. [explain why.]

Exercise 2

Plot the phase portrait for the anharmonic oscillator
d2x/dt2 = -x + a x3.
Set y=dx/dt, thus we have the system of equations
dx/dt=y
dy/dt=-x + a x3

Fixed Points:
(i) x=0, y=0
(ii) x=1/sqrt(a), y=0
(iii) x=-1/sqrt(a), y=0

Phase curves are given by
dy/dx = (-x + a x3)/y ==> y2/ + x2/2 - a x4/4 = C

Let us define the function f(x,y)=y2/ + x2/2 - a x4/4
and plot it. Choose, for example a=0.01, so that fixed points are (0,0), (10,0), (-10,0).
Using gnuplot we have the commands:
a=0.01
set xrange[-15:15]
set yrange[-10:10]
splot y**2/2.+x**2/2.-a*x**4/4. w l

Then make a contour plot of f(x,y) which is equivalent to plotting the the phase curves. [explain why.]
Using gnuplot we have the commands:
unset surface
set contour
set cntrparam levels incremental 0.0,5.0,70
set view 0,0
unset clabel
unset key
splot y**2/2.+x**2/2.-a*x**4/4. w l
[Note that C=0 at the fixed point (0,0) while the curve with C=25 contains the points (+-10,0).]

A smoother graph is obtained if we use:
set isosamples 50
splot y**2/2.+x**2/2.-a*x**4/4. w l

Τέλος, γιά να τυπώσετε το γράφημά σας ακολουθήστε την εξής διαδικασία:
set term post
set output 'phaseportrait.ps'
replot

The graph may look better if we use:
set grid
set xtics -15,5,15
set ytics -10,5,10
set xtics font "Helvetica, 14"
set ytics font "Helvetica, 14"
splot y**2/2.+x**2/2.-a*x**4/4. w l

Exercise 3

Study the Lotka-Volterra model.
(a) Find the equilibrium points for a,b,c,d of your choice (e.g., a=1, b=1, c=0.01, d=0.02).
(b) Solve numerically the system of equations for various initial conditions (use, e.g., matlab).
(c) Plot the populations as a function of time.
(d) Plot the phase portrait.
(a)
See the Lecture Notes.
(b), (c)
Here is a guide.

We whould do somethimg similar to the problem of vortices (Lab 03/11/10, Exercise 1).

Here is a basic code in matlab:
t0=0;
t1=10;
y0 = [1 1];
[t,y] = ode45('lotka3',[t0,t1],y0);
plot...

In the above code we use the function:
function yp=lotka3(t,y)
h1 = y(1) - y(1)*y(2);
h2 = -y(2) + 2.0*y(1)*y(2);
yp = [h1 h2]';
(d)
We use gnuplot and similar commands is in Exercise 2. We should use the integral for the model given in the Lecture notes and make a contour plot for it.

Alternatively, we may use matlab to directly solve the differential equations (and then plot the phase portrait), for example:
t0=0;
t1=10;
y0 = [1 1];
[t,y] = ode45('lotka3',[t0,t1],y0);
plot(y(:,1),y(:,2));
y0 = [1 2];
[t,y] = ode45('lotka3',[t0,t1],y0);
hold on
plot(y(:,1),y(:,2));
etc...




Online help for matlab is available in, e.g.,