Di⁄erential equations with MATLAB: an (advanced) introduction

36
Di/erential equations with MATLAB: an (advanced) introduction compilation of lab materials by Dr. Yuriy Rogovchenko Version 1.2 - Revised on April 11, 2011 1 Stable and sti/ di/erential equations MATLAB has several solvers for di/erential equations (DEs). The choice of the solver depends on the type of the problem and its properties. Consider a rst order di/erential equation ! y 0 = ! f (t; ! y (t)) ; (1) where ! y 2 R n is an n-dimensional column vector, t 2 R; and ! f : R R n ! R n is a vector function, ! y (t)= 0 B B B @ y 1 (t) y 2 (t) . . . y n (t) 1 C C C A ; ! f (t; ! y (t)) = 0 B B B @ f 1 (t; ! y (t)) f 2 (t; ! y (t)) . . . f n (t; ! y (t)) 1 C C C A : Denition 1 The Jacobian matrix J is dened as an m m matrix with elements J hj (t; ! y (t)) = @f k (t; ! y )(t) @y j : Example 2 Consider the following vector di/erential equation (the system of two rst order di/erential equations) ! y 0 = 2y 4 1 (t)+3y 2 2 (t) sin 3 t y 2 1 (t) 3y 2 (t) 2t 1

Transcript of Di⁄erential equations with MATLAB: an (advanced) introduction

Page 1: Di⁄erential equations with MATLAB: an (advanced) introduction

Di¤erential equations with MATLAB: an(advanced) introduction

compilation of lab materials by Dr. Yuriy Rogovchenko

Version 1.2 - Revised on April 11, 2011

1 Stable and sti¤ di¤erential equations

MATLAB has several solvers for di¤erential equations (DEs). The choice ofthe solver depends on the type of the problem and its properties. Considera �rst order di¤erential equation

�!y 0 = �!f (t;�!y (t)) ; (1)

where �!y 2 Rn is an n-dimensional column vector, t 2 R; and �!f : R�Rn !Rn is a vector function,

�!y (t) =

0BBB@y1 (t)y2 (t)...

yn (t)

1CCCA ; �!f (t;�!y (t)) =

0BBB@f1 (t;

�!y (t))f2 (t;

�!y (t))...

fn (t;�!y (t))

1CCCA :De�nition 1 The Jacobian matrix J is de�ned as an m � m matrix withelements

Jhj (t;�!y (t)) = @fk (t;

�!y ) (t)@yj

:

Example 2 Consider the following vector di¤erential equation (the systemof two �rst order di¤erential equations)

�!y 0 =�2y41 (t) + 3y

22 (t)� sin3 t

y21 (t)� 3y2 (t)� 2t

�1

Page 2: Di⁄erential equations with MATLAB: an (advanced) introduction

or

y01 (t) = 2y41 (t) + 3y

22 (t)� sin3 t;

y02 (t) = y21 (t)� 3y2 (t)� 2t:

Then the Jacobian

J (t;�!y (t)) =�8y31 (t) 6y2 (t)2y1 (t) �3

�:

Remark 3 For a scalar �rst order di¤erential equation

y0 = f(t; y (t) ; (2)

the Jacobian is simply

J(t; y (t) =@f(t; y (t)

@y= fy(t; y (t) :

MATLAB can also compute the Jacobian with the command jacobian(f,v). Read the help.

De�nition 4 We say that a scalar di¤erential equation (2) is

1. stable at a point (t�; y (t�)) if fy (t�; y (t�)) < 0;

2. unstable at a point (t�; y (t�)) if fy (t�; y (t�)) > 0;

3. sti¤ at a point (t�; y (t�)) if fy (t�; y (t�)) � 0; where the symbol �means �much smaller than.�

De�nition 5 We say that a system of di¤erential equations (a vector dif-ferential equation (1) is

1. stable at a point (t�;�!y (t�)) if the real parts of all eigenvalues of the

Jacobian matrix J (t�;�!y (t�)) < 0 are negative;

2. sti¤ at a point (t�;�!y (t�)) if the real parts of more than one eigenvalue

of the Jacobian matrix J (t�;�!y (t�)) are negative and wildly di¤erent.

2

Page 3: Di⁄erential equations with MATLAB: an (advanced) introduction

The stability of a di¤erential equation or a system of di¤erential equationsis determined by the values of the Jacobian matrix which can change overtime. Therefore, an equation or a system can be stable at some instants andunstable at other.

Example 6 Suppose that we are given a system of three di¤erential equa-tions whose Jacobian matrix has eigenvalues �1 (t) = 9�t2; �2;3 (t) = �t�it2;where i2 = �1: Then the system is stable for all values of t satisfying the fol-lowing conditions:

9� t2 < 0;�t < 0;

that is, for all t > 3: Furthermore, for t large the system is also sti¤ becauseboth eigenvalues are negative and wildly di¤erent.

If a di¤erential equation or a system of di¤erential equations are sti¤,solutions to associated initial value problems are determined on time scalesthat are radically di¤erent from each other. This forces numerical schemesto employ small time steps in order to follow the solution. Sti¤ problemsare always stable, that is, numerical approximations converge rapidly to asolution. Such problems are common, for instance, in weather prediction orchemical reactions.

Example 7 Consider the linear system of di¤erential equations�!y 0 = A�!y ; (3)

where

A =

��1001 999999 �1001

�:

Then the Jacobian J = A; and the eigenvalues are �1 = �2000 and �2 = �2:According to De�nition 5, this system is sti¤. Its analytic solution is

�!y = C1e�2t�11

�+ C2e

�2000t��11

�;

where C1 and C2 are arbitrary constants determined from the initial condi-tions. If

y1 (0) = 0; y2 (0) = 2;

then C1 = C2 = 1; and the components y1 and y2 of the solution is shown inFigure 1.

3

Page 4: Di⁄erential equations with MATLAB: an (advanced) introduction

Note that even after our solution becomes nearly constant, nearby solu-tions are changing quite rapidly. This causes trouble for numerical methodssince they introduce small perturbations in the solution and may jump fromone solution in the family to another. To cope with this problem, one usesappropriate ODE solvers designed to handle sti¤ problems.

2 Qualitative theory of dynamical systems inthe plane

2.1 Stability of equilibria

Consider a two-dimensional autonomous system of di¤erential equations

x0 = P (x; y) ;y0 = Q (x; y) :

(4)

De�nition 8 We say that (x0; y0) is an equilibrium point (critical point,stationary point, etc.) if P (x0; y0) = 0 and Q (x0; y0) = 0: In this case,x (t) = x0; y (t) = y0 is a stationary (steady-state) solution of (4).

De�nition 9 We call a critical point isolated if there exists a ball centeredat this point which does not contain other critical points of (4).

De�nition 10 We say that a critical point (x0; y0) is stable (see Figure 2)if for any ball B" of radius " there is a smaller ball B� of radius � such thatany solution (x (t) ; y (t)) of (4) that enters the ball B� at some instant t�remains in the ball B" for all t � t�:

De�nition 11 We say that a critical point (x0; y0) is asymptotically stable(see Figure 3) if it is stable and, in addition, for any solution (x (t) ; y (t)) ;one has (x (t) ; y (t))! (x0; y0) as t! +1:

De�nition 12 We say that a critical point (x0; y0) is unstable if it is notstable. That is, for any choice of ball B" solution, (x (t) ; y (t)) ; leaves it ast! +1 even if at some instant (x (t) ; y (t)) is very close to (x0; y0) :

4

Page 5: Di⁄erential equations with MATLAB: an (advanced) introduction

­5 0 5 10 15 20­0.5

0

0.5

1

1.5

2Solution of a stiff system

time t

solu

tions

 y1,

 y2

y1y2

Figure 1: Solutions to a sti¤ system of linear di¤erential equations.

(x0,y0)

B

B

Figure 2: Stable critical point (x0; y0) of (4).

5

Page 6: Di⁄erential equations with MATLAB: an (advanced) introduction

(x0,y0)

B

B

Figure 3: Asymptotically stable critical point (x0; y0) of (4).

Stable critical points attract solutions, whereas asymptotically stable crit-ical points attract solutions much stronger so that they eventually come in-de�nitely close to critical point. Unstable critical points repel solutions.Since, in general, we cannot solve (4) to obtain explicit solutions, our goal

is to study critical points of (4) and their stability properties.

De�nition 13 We call fx (t) ; y (t) : � < t < �g an orbit (trajectory) of (4).The orbits are sketched in the xy-plane, called phase plane or Poincaré plane.

Equations in (4) can be also written in the form

dy

dx=Q (x; y)

P (x; y): (5)

For each �xed (x�; y�) ; the right hand side of (5) de�nes the slope of thevector �eld (direction �eld) generated by (4) or (5). The direction �eldgives an idea about location and behavior of trajectories because trajectoriesshould be tangent to segments with the given slope.

De�nition 14 We call a phase portrait of (4) a sketch where several orbitsare presented together with direction of motion along them.

6

Page 7: Di⁄erential equations with MATLAB: an (advanced) introduction

Figure 4: A stable limit cycle.

2.2 Periodic solutions and limit cycles

De�nition 15 A closed trajectory which is approached by other trajectoriesas t! �1 or t! +1 is called a limit cycle.

On each side of a limit cycle, other trajectories can be either spiralingtowards the limit cycle or spiraling away. If trajectories on both sides arespiraling towards limit cycle, it is called stable. If trajectories on both sidesare spiraling away, the limit cycle is called unstable. If the limit cycle attractssolutions on one side and repels on the other, it is called semi-stable, seeFigures 4, 5, 6 and 7.

Example 16 Classify limit cycles of the following system in polar coordi-nates

r0 = r (r � 1)2 (3� r) ; �0 = �1: (6)

It is easy to see that the solution goes clockwise around the origin. Thedi¤erential equation for r has an attracting �xed point at r = 3 and tworepelling at r = 0 and r = 1: Thus, (6) has a stable limit cycle of radiusthree, a semi-stable limit cycle of radius 1, whereas the origin is a repellor,see Figure 8.

7

Page 8: Di⁄erential equations with MATLAB: an (advanced) introduction

Figure 5: An unstable limit cycle.

Figure 6: A semi-stable limit cycle.

8

Page 9: Di⁄erential equations with MATLAB: an (advanced) introduction

Figure 7: A semi-stable limit cycle.

y

x

Figure 8: Phase potrait of system (6). The system have a stable limit cycle ofradius three, a semi-stable limit cycle of radius 1 and the origin is a repelling�xed point.

9

Page 10: Di⁄erential equations with MATLAB: an (advanced) introduction

Example 17 Consider the following system of di¤erential equations

r0 = r (1� r) (r � 2) ; �0 = 1: (7)

Observe that solutions go counterclockwise around the origin. The di¤erentialequation for r has two attracting �xed points at r = 0 and r = 2 and arepelling point at r = 1: Thus, the given system have a stable limit cycleof radius two, an unstable limit cycle of radius 1, whereas the origin is anattractor, see Figure 9.

y

x

Figure 9: Phase potrait of system (7). The system have a stable limit cycleof radius two, an unstable limit cycle of radius 1 and the origin is a attracting�xed point.

Theorem 18 If the system (4) has a closed trajectory, there should be acritical point inside.

Theorem 19 (Non-existence of Limit Cycles) Let D be a simply con-nected region of the phase plane and assume that

@P (x; y)

@x+@Q (x; y)

@y

10

Page 11: Di⁄erential equations with MATLAB: an (advanced) introduction

has constant sign. Then the system (4) has no closed trajectories which lieentirely in D:

Example 20 Consider the system

x0 = 2x+ y + x3; y0 = 3x� y + y3:Observe that

@P (x; y)

@x+@Q (x; y)

@y= 1 + 3

�x2 + y2

�> 1

for all (x; y) 2 R2: Thus, the given system has no closed trajectories in thewhole phase plane.

Example 21 For the system

x0 = �5x+ y + x3; y0 = 3x+ 2y + y3;

we have@P (x; y)

@x+@Q (x; y)

@y= 3

�x2 + y2 � 1

�:

By Theorem 19, there are no closed trajectories which lie entirely in theinterior or exterior of the unit circle.

Theorem 22 (Poincaré-Bendixson) Consider the system (4), where P;Qare continuous with their derivatives in some domain D: Let D1 be a subdo-main of D and R = D1 [ @D1: Suppose that R does not contain equilibriumpoints of system (4) and there exists t0 2 R such that at t = t0 the trajectory(x (t) ; y (t)) of system (4) enters R and remains there for all t � t0: Theneither this trajectory is closed or it spirals towards a closed trajectory in R:

2.3 ODE solvers in MATLAB

MATLAB has several solvers for di¤erential equations.

Solver Problem type Order of accuracy When to useode45 Nonsti¤ Medium Most of the timeode23 Nonsti¤ Low Moderately sti¤ problemsode113 Nonsti¤ Low to high Computationally intensive DEsode15s Sti¤ Low to medium Sti¤ problems, when ode45 is slowode23s Sti¤ Low Sti¤ systemsode23t Moderately sti¤ Low Moderately sti¤ problemsode23tb Sti¤ Low Sti¤ systems

11

Page 12: Di⁄erential equations with MATLAB: an (advanced) introduction

The ODE solvers can do more complicated things, too; read the docu-mentation carefully.

2.4 Getting started

Write the n-th order ordinary di¤erential equation

y(n) = f�t; y; y0; : : : ; y(n�1)

�as a system of �rst-order equations by making the substitutions

y1 = y; y2 = y0; : : : ; yn = y

(n�1):

Then

y01 = y2;

y02 = y3;

...

y0n = f (t; y1; y2; : : : ; yn)

is a system of n �rst order di¤erential equations.

Example 23 The initial value problem

y000 � 3y00 � yy0 = 0;y (0) = 0; y0 (0) = 1; y00 (0) = �1

can be written as the initial value problem for the following system of �rstorder di¤erential equations

y01 = y2;

y02 = y3;

y03 = 3y3 + y1y2;

y1 (0) = 0; y2 (0) = 1; y3 (0) = �1:

Before anything can be done with a di¤erential equation, a so-called m-file de�ning the right hand side must be created. Open your favorite texteditor, enter the following to code the �rst order system as an m-file that

12

Page 13: Di⁄erential equations with MATLAB: an (advanced) introduction

accepts two arguments t and y; and returns a three-component column vectorthat contains information regarding the right-hand side of our system ofdi¤erential equations.

function ydot = syst(t,y)ydot = zeros(3, 1);ydot(1) = y(2);ydot(2) = y(3);ydot(3) = 3*y(3)+y(2)*y(1);

and save it as syst.mAlternatively, you can write a shorter presentation for your function in

the form

function ydot = syst(t,y)ydot = [y(2); y(3); 3*y(3)+y(2)*y(1)];

and save it as syst.mThe �rst line de�nes a function syst, a function of time t and the state

vector y, which returns the value of the right hand side of the given system.Since the system is autonomous, time does not appear explicitly. The nextline initializes the function to be a matrix with 3 rows and 1 column, i.e.,a column vector consisting of zeros. The three �nal lines then compute thethree coordinates of the right hand side. The lines end with a semi-colon toprevent the result to be printed when the function is called.Apply a solver function to the problem. The general calling syntax for

the ODE solvers is

[tout,yout] = solver(@F, tspan, y0)

where solver is a solver function like ode45. The three input arguments are:

F string containing the name of the function describing the ODE �le

tspan vector of time values where [t0 tfinal] causes the solver to in-tegrate from t0 to tfinal

y0 column vector of initial conditions at the initial time t0

To use the ode45 solver to �nd a solution of the sample initial valueproblem (IVP) on the time interval [0 1], the calling sequence is

13

Page 14: Di⁄erential equations with MATLAB: an (advanced) introduction

[tout, yout] = ode45(@syst, [0 1], [0; 1; -1])

This invokes the Runge-Kutta solver ode45 with the di¤erential equationde�ned by the �le syst.m. The sign �@� tells MATLAB that syst is afunction. The equation is solved on the time interval t 2 [0; 1] with initialcondition (y (1) ; y (2) ; y (3)) = (0; 1;�1) : The solver obtains results at timesstored in the one-column vector with corresponding solution in the three-column matrix yout. Each row in solution array yout corresponds to a timeinstant in the column vector tout. Also, in the case of the sample IVP,yout(:,1) is the solution, yout(:,2) is the derivative of the solution, andyout(:,3) is the second derivative of the solution. The solver has an errorcontrol and adjusts the time step to try to make the error within a certainbound. Hence, the number of steps taken in not known in advance. Checkthe actual sizes by using, for instance, the command size(yout). Furtherinformation on the solver can be obtained by typing help ode45.

2.5 Plotting direction �eld

Plotting slope �elds in MATLAB requires a bit of work. The following pro-gram utilizes the built-in command quiver(x,y,dx,dy) that plots an n� narray of vectors with x and y components speci�ed by the n�n matrices dxand dy, based at the xy-points in the plane whose x and y coordinates arespeci�ed by the n� n matrices x and y:

% slope field program sfield.mn = 20; % no of subintervalsa = -10; b = 10; % x-intervalc = -10; d = 10; % y-intervalh = (b-a)/n; k = (d-c)/n; % x- and y-step sizesy1 = a : h : b; % y1-subdivision pointsy2 = c : k : d; % y2-subdivision points[y1,y2] = meshgrid(y1,y2); % grid of pointsf = 2*y1- y2; % define f(x,y)t = atan(f); % angle of inclinationdy1 = cos(t); dy2 = sin(t); % xy-components of arrowquiver(y1,y2,dy1,dy2) % plot slope fieldaxis([a b c d]) % viewing windowgrid on % draw grid lines

14

Page 15: Di⁄erential equations with MATLAB: an (advanced) introduction

title(�Direction field�);xlabel(�y_1(t)�);ylabel(�y_2(t)�), shg

However, you need not be concerned about these matrices of coordinatesand components �only the number n of subintervals in each direction, thedesired viewing window a � b; c � d; and the expression f de�ning the right-hand side of the di¤erential equation y0 = f(x; y) need be altered when theprogram s�eld is de�ned by saving the commands listed above in the text �lesfield.m. The result is shown in Figure 10. Alternatively, these commands

­10 ­5 0 5 10­10

­8

­6

­4

­2

0

2

4

6

8

10Direction field

y1(t)

y 2(t)

Figure 10: Direction �eld.

could be entered individually in command mode. You can also add severaltrajectories to the plot with vector �eld.

3 Case study: the van der Pol equation

The celebrated van der Pol equation is

y00 � ��1� y2

�y0 + y = 0;

where � > 0 is a scalar parameter.

15

Page 16: Di⁄erential equations with MATLAB: an (advanced) introduction

3.1 Rewriting the equation

Introducing new variables y1 and y2 by y1 = y; y2 = y0; we express this equa-tion as a system of �rst-order di¤erential equations required by MATLAB,

y01 = y2;

y02 = ��1� y21

�y2 � y1:

Open your favorite text editor, enter the following

function ydot = vdp1(t, y)ydot = zeros(2, 1);ydot(1) = y(2);ydot(2) = (1-y(1)^2)*y(2)-y(1);

and save it as vdp1.m . This simple �le assumes a value of 1 for �; y1 andy2 become y(1) and y(2), elements in a two-element vector.Note that this ODE �le does not actually use the t argument in its

computations. It is not necessary for it to use the y argument either � insome cases, for example, it may just return a constant. The t and y variables,however, must always appear in the input argument list.

3.2 Calling the solver

Once the system is coded in an m-�le, you can use the MATLAB ODE solversto solve the system on a given time interval with a particular initial conditionvector. For example, to use ode45 to solve the van der Pol equation on timeinterval [0; 20] with an initial value of 2 for y(1) and an initial value of 0 fory(2), you use the command

[tout, yout] = ode45(@vdp1, [0 20], [2; 0]);

The resulting output [tout, yout] is a column vector of time pointstout and a solution array yout. Each row in solution array yout correspondsto a time returned in column vector tout.

3.3 Viewing the Results

Use the plot command to view solver output.

16

Page 17: Di⁄erential equations with MATLAB: an (advanced) introduction

plot(tout, yout(:,1), �--�, tout, yout(:,2), �--�)title(�Solution of van der Pol equation, mu = 1�);xlabel(�time t�);ylabel(�solution y�);legend(�y1�, �y2�)

The result is presented in Figure 11. To use speci�c colors, you can use the

0 5 10 15 20­3

­2

­1

0

1

2

3Solution of van der Pol equation, mu = 1

time t

solu

tion 

y

y1y2

Figure 11: Solutions of the van der Pol equation, � = 1:

following command:

plot(tout, yout(:,1), �r�, tout, yout(:,2), �b-�)

A new window opens with the plot, see Figure 12. Here yout(:,1)meanseverything in the �rst column in yout and ´r´ gives a red continuous curve.The second column is shown in blue with a dash-dotted line. Use help plotto see how to control the plot.A plot in the phase plane of the solution may be obtained by

plot(yout(:,1), yout(:,2))

generating the phase portrait presented in Figure 13.

17

Page 18: Di⁄erential equations with MATLAB: an (advanced) introduction

Note, that in the MATLAB command window you can scroll throughprevious commands by using the up and down arrow keys. This is mostuseful for editing and reusing previous commands.

3.4 Facing a sti¤ problem

The Runge-Kutta method used above is a good choice for a standard solver.However, for sti¤ systems of di¤erential equations the error control will forcethe solver to take extremely small steps, and more advanced methods areneeded. Such systems are called sti¤, and this occurs typically when thedynamics of the solutions involves both slow and fast changes. Methods forsti¤ problems are generally implicit, that is, in each time step a non-linearset of algebraic equations must be solved. This is time-consuming, but theadvantage is that much larger steps can be taken and the overall performanceis signi�cantly improved.To illustrate sti¤ness, consider the van der Pol equation with � = 1000:

As we will observe, when � is increased to 1000, the solution to the van derPol equation changes dramatically and exhibits oscillation on a much longertime scale. Prepare a �le vdp1000.m as follows:

function ydot = vdp1000(t, y)ydot = zeros(2, 1);ydot(1) = y(2);ydot(2) = 1000*(1-y(1)^2)*y(2)-y(1);

and save it as vdp1000.mSolve it in the same manner as above, but on a much smaller interval

t 2 [0; 1] by calling the solver

[tout,yout] = ode45(@vdp1000, [0 1],[2; 0]);

Check how many steps where taken for the solution by typing

size(tout)ans =

3633 1

The array has 3633 rows (and 1 column), so this is the number of steps.MATLAB also has an implicit solver for sti¤ systems, ode15s, which may be

18

Page 19: Di⁄erential equations with MATLAB: an (advanced) introduction

0 5 10 15 20­3

­2

­1

0

1

2

3Solution of van der Pol equation, mu = 1

time t

solu

tion 

y

y1y2

Figure 12: Solutions of the van der Pol equation, � = 1 (colored graphics).

­2.5 ­2 ­1.5 ­1 ­0.5 0 0.5 1 1.5 2 2.5­3

­2

­1

0

1

2

3Limit cycle for the van der Pol equation, mu = 1

solution y1

solu

tion 

y2

y1

Figure 13: Limit cycle for the van der Pole equation in the phase plane,� = 1:

19

Page 20: Di⁄erential equations with MATLAB: an (advanced) introduction

used to solve vdp1000. Retain the initial condition vector of [2; 0], but use atime interval of [0 3000]. For scaling purposes, plot just the �rst componentof y(t).

[tout, yout] = ode15s(@vdp1000, [0 3000], [2; 0]);plot(tout, yout(:,1), �o�);title(�Solution of van der Pol equation, mu = 1000�);xlabel(�time t�);ylabel(�solution y�);

The result is seen in Figure 14. We can also plot the solution in the phaseplane by using the command

plot(yout(:,1), yout(:,2))

see Figure 15. You can check again how many steps were needed for thecomputation by typing

size(tout)ans =

592 1

It appears that ode15s handles the situation much more e¢ ciently!

3.5 Handling equation with a parameter (advanced!)

Rather than de�ne individual m-�les for the di¤erent versions of the van derPol equation, it is convenient to consider a parametrized family and thenafterwards specify the relevant values of the parameter �. De�ne the �le a�le vdppar.m as follows:

function ydot = vdppar(t, y, mu)ydot = zeros(2, 1);ydot(1) = y(2);ydot(2) = mu*(1-y(1)^2)*y(2)-y(1);

and save it as vdppar.mTo obtain a solution with � = 1; type

[tout, yout] = ode45(@vdppar, [0 20], [2; 0], [], 1);

20

Page 21: Di⁄erential equations with MATLAB: an (advanced) introduction

0 500 1000 1500 2000 2500 3000­2.5

­2

­1.5

­1

­0.5

0

0.5

1

1.5

2Solution of van der Pol equation, mu = 1000

time t

solu

tion 

y

Figure 14: Solution of the van der Pol equation, � = 103:

­2.5 ­2 ­1.5 ­1 ­0.5 0 0.5 1 1.5 2­1500

­1000

­500

0

500

1000

1500Solution of van der Pol equation, mu = 1000

time t

solu

tion 

y

Figure 15: Limit cycle for the van der Pol equation, � = 103:

21

Page 22: Di⁄erential equations with MATLAB: an (advanced) introduction

To draw a phase portrait, you will need more than just one solution. Thefollowing procedure in a �le phasport.m helps you:

function phasport(@F, tspan, plotrange, @solver)clf;axis(plotrange);hold on;xlabel(�y1�);ylabel(�y2�);title(�Limit cycle for van der Pol equation�);

[y0(1), y0(2), button] = ginput(1);while button == 1,[tout, yout]=feval(@solver, @F, tspan, y0);plot(yout(:,1), yout(:,2));[tout2, yout2]=feval(solver, @F, -tspan, y0);plot(yout2(:,1), yout2(:,2));[y0(1), y0(2), button] = ginput(1);end;

Please note that in some newer versions of MATLAB the �rst line of the�le phasport.m should be changed to

function phasport(F, tspan, plotrange, solver)

in order to make it work.In the procedure equations is the name of the m-�le de�ning the equa-

tions, tspan is the time interval wanted for the solutions, plotrange is ofthe form [y1min y1max y2min y2max] and de�nes the plotting window inthe phase plane, and solver is the name of a MATLAB di¤erential equationsolver. The commands clf and hold on tell MATLAB to clear current�gure window and to retain current graph in �gure; ginput(1) indicatesgraphical input from mouse or cursor. Finally, if fname is a quoted stringcontaining the name of a function (usually de�ned within �le having a .m�le extension), then feval(fname, x1, ..., xn) evaluates that functionat the given arguments.When called, a plotting window opens, and the cursor changes into a

cross-hair. Clicking with the left mouse button at a point in the phase spacegives the orbit through that point. First the equations are integrated forwards

22

Page 23: Di⁄erential equations with MATLAB: an (advanced) introduction

in time and this part of the orbit is plotted. Then the same is done backwardsin time. In either time direction the orbit may become unbounded, and awarning may be printed in the MATLAB command window. This is generallyof no consequence, but if you have chosen tspan too large, computations maybe unacceptably slow. Then press �control-c� in the MATLAB commandwindow to break the execution and adjust the time interval. When an orbitis drawn you can continue clicking at points, and when you are satis�ed clickany other mouse button in the window, and the procedure terminates.

­3 ­2 ­1 0 1 2 3­3

­2

­1

0

1

2

3

y1

y2

Limit cycle for van der Pol equation

Figure 16: Phase portrait for the van der Pol equation, � = 1:

Calling the procedure by typing

phasport(@vdp1, [0 30], [-3 3 -3 3], @ode45)

and making several clicks with the mouse, we generate something like Figure16. The following procedure includes a parameter �:

function phasportpar(@F, tspan, plotrange, @solver, parameter)clf;axis(plotrange);hold on;

23

Page 24: Di⁄erential equations with MATLAB: an (advanced) introduction

xlabel(�y1�);ylabel(�y2�);title(sprintf(�Limit cycle for van der Pol equation, mu = %f�,parameter));

[y0(1), y0(2), button] = ginput(1);while button == 1,[tout, yout]=feval(@solver, @F, tspan, y0, [], parameter);plot(yout(:,1), yout(:,2));[tout2, yout2]=feval(solver, @F, -tspan, y0, [], parameter);plot(yout2(:,1), yout2(:,2));[y0(1), y0(2), button] = ginput(1);end;

Calling the procedure by typing

phasportpar(@vdppar, [0 30], [-3 3 -3 3], @ode45, 1)

and making several clicks with the mouse, we generate nearly the same phaseportrait as in Figure 17.

4 Additional ODE software in MATLAB (ad-vanced!)

Material in this section is adopted from the book by Polking and Arnold [3].

4.1 Downloading optional programs

The MATLAB programs dfield, pplane, and odesolve are not distributedwith MATLAB. They are MATLAB function m-�les and are available fordownload over the internet. There are versions of dfield and pplane writtenfor use with all recent versions of MATLAB. However, odesolve is new, andonly works with MATLAB version 6.0 and later. The solvers are the samefor all versions of MATLAB.The following three step procedure will insure a correct installation, but

the only important point is that the �les must be saved as MATLAB m-�lesin a directory on the MATLAB path.

24

Page 25: Di⁄erential equations with MATLAB: an (advanced) introduction

� Create a new directory with the name odetools (or choose a name ofyour own). It can be located anywhere on your directory tree, but putit somewhere where you can �nd it later.

� In your web browser, go to http://math.rice.edu/~d�eld/. For each�le you wish to download, click on the link. In Internet Explorer,you are given the option to save the �le. In Netscape, the �le for thesoftware will open in your browser, and you can save the �le using theFile menu. In either case, save the �le with the subscript .m in thedirectory odetools.

� Open the path tool by executing the command pathtool in the MAT-LAB command window, or by selecting File!Set Path. Follow theinstructions for adding the directory odetools to the path. If you areasked if you want the change to be permanent, say yes.

From this point on, the programs will be available in MATLAB.

4.2 DFIELD7

The MATLAB routine dfield7 is useful for plotting the direction �eld fora given di¤erential equation at a large number of points which allows theuser to get some geometric insight into the properties of solutions of theequation. To see dfield7 in action, enter dfield7 at the MATLAB prompt.After a short wait, a new window will appear with the label dfield7 Setup.The appearance may di¤er slightly depending on your computer, but thefunctionality is the same on all machines.The di¤erential equation is entered in the edit box entitled �The di¤er-

ential equation�of the dfield7 Setup window. There is also an edit box forthe independent variable and several edit boxes are available for parameters.The default values in �The display window�limit the independent variable tto �2 � t � 10 and the dependent variable x to �4 � x � 4: At the bottomof the dfield7 Setup window there are three buttons labelled Quit, Revert,and Proceed. Click the button with the label Proceed. After a few secondsanother window will appear, this one labeled dfield7 Display.There is a pair of buttons on the dfield7 Display window: Quit and

Print. There are several menus: File, Edit, Options, Insert, and Help. Belowthe direction �eld there is a small window giving the coordinates of the cur-sor, and a larger message window through which d�eld6 will communicate

25

Page 26: Di⁄erential equations with MATLAB: an (advanced) introduction

with us. Note that the last line of this window contains the word �Ready,�indicating that dfield7 is ready to follow orders. To solve a given di¤er-ential equation with initial condition x(t0) = x0; we move the mouse to thepoint (t0; x0), using the cursor position display at the bottom of the �gureto improve our accuracy, and then click the mouse button. The computerwill compute and plot the solution through the selected point, �rst in thedirection in which the independent variable is increasing (the �Forward�di-rection), and then in the opposite direction (the �Backward�direction).Youmay start by going to the setup window and selecting Gallery!default

equation. The correct data will be entered. Click Proceed to transfer thisinformation and begin computation of the direction �eld in the dfield7Display window. Select Options!Keyboard input in the dfield7 Displaywindow and compute solutions for several initial conditions.Return to the dfield7 Setup window and select Edit!Clear all before

you start a new task. Note that there are options on the Edit menu to clearparticular regions of the dfield7 Setup window and each of these optionspossesses a keyboard accelerator. Should your data entry become hopelesslymangled, click the Revert button to restore the original entries. If the ini-tial value problem contains no parameters, leave the parameter �elds in thedfield7 Setup window blank. Click the Proceed button to transfer the in-formation in the dfield7 Setup window to the dfield7 Display window andstart the computation of the direction �eld. Choosing the initial point forthe solution curve with the mouse is convenient, but it is often di¢ cult to beaccurate, even with the help of the cursor position display. Instead, in thedfield7 Display window, select Options!Keyboard input.If desired (this is not necessary), you can specify a computation interval

by clicking the �Specify a computation interval� checkbox in the dfield7Keyboard Input window and �lling in the starting and ending times of thedesired solution interval. To get more accuracy, we will increase the resolutionusing the zoom tools in dfield7. Select Edit!Zoom in the dfield7 Displaywindow, then single-click the (left) mouse button in the dfield7 Displaywindow near the point of interest. Additional �zooms� require that yourevisit Edit!Zoom in before clicking the mouse button to zoom. There is afaster way to zoom in that is platform dependent. If you have a mouse withmore than one button, click the right mouse button at the zoom point (orcontrol-click the left mouse button at the zoom point). It is also possible tozoom in by dragging a �zoom box�. If you have a two button mouse, thiscan be done by depressing the right mouse button, then dragging the mouse.

26

Page 27: Di⁄erential equations with MATLAB: an (advanced) introduction

Once the zoom box is drawn around the area of interest, release the mousebutton and the contents of the zoom box will be magni�ed to the full size ofthe display window. The same e¤ect can be achieved on a Macintosh with aone button mouse by depressing the option key while clicking and dragging.Dfield7 allows you to �zoom back�to revisit any previously used window.Select Edit!Zoom back in the dfield7 Display window. This will open thedfield7 Zoom back dialog box. Select the window you wish to revisit andclick the Zoom button.All of the features of MATLAB are available while d�eld6 is open. You

can use MATLAB commands to plot to the dfield7 Display window, or youcan open another �gure window by typing �gure at the MATLAB prompt.When more than one �gure is open, it is important to remember that plottingcommands are directed to the current �gure. This is always the most recentlyvisited window. You can make a particular �gure active by clicking on it.If the dfield7 Setup window is the current �gure, your plot command willbe directed to it. It will be executed correctly, but it will not change theappearance of the window, so it will look as though nothing happened. Thisis an annoying outcome. When you have more than one �gure window open,it is a good idea to click on the �gure where you want a plot to be executedjust before issuing the command.If you want a subscripted quantity to appear on a MATLAB �gure win-

dow it is only necessary to precede the subscript by an underscore (_). Ifthe subscript contains more than one letter, put the entire subscript betweencurly brackets ({}). If you have a superscripted quantity, precede the su-perscript with a caret (^). Most Greek letters, including some upper caseletters, can be typed by spelling out the name, preceded by a backslash. Forexample, you can use nalpha, nbeta, ngamma, ntheta, nphi, nDelta, nOmega,and nTheta.The appearance of the Display Window can be changed in a variety of

ways. The menu item Options!Windows settings provides several ways toalter the appearance of the dfield7 Display window. Selecting this item willopen the dfield7 Windows settings dialog box The �rst option involves thethree radio buttons, and allows you to choose between a line �eld, a vector�eld, or no �eld at all. Some people prefer to use a vector �eld to a directionline �eld. In a vector �eld, a vector is attached to each point instead of theline segment used in a direction �eld. The vector has its base at the point inquestion, its direction is the slope, and the length of the vector re�ects themagnitude of the derivative. Click the Change settings button to make any

27

Page 28: Di⁄erential equations with MATLAB: an (advanced) introduction

change you select.There is an edit box in the dfield7 Window settings dialog that allows

the user to choose the number of �eld points displayed. The default is 20points in each row and in each column. Change this entry to 10, hit Enter,then click the Change settings button to note the a¤ect on the direction �eld.The design of dfield7 includes the de�nition of two windows: the dfield7

Display window and the calculation window. When you start dfield7, thecalculation window is 3.5 times as large as the display window in each di-mension. The computation of a solution will stop only when the solutioncurve leaves the calculation window. This allows some room for zoomingto a larger display window without having incomplete solution curves. Italso allows for some reentrant solution curves �those which leave the dis-play window and later return to it. The third item in the dfield7 Windowsettings dialog box controls the relative size of the calculation window. Itcan be given any value greater than or equal to 1. The smaller this numberthe more likely that reentrant solutions will be lost. The default value of 3.5seems to meet most needs, but if you are losing too many reentrant solutionsyou can increase this parameter.It is possible to mark the points at which the computation of solutions is

started. To do this, select Options!Mark initial points. To stop doing so,select the same option to uncheck it. Initial points that are already plottedcan be erased with the command Edit!Erase all marked initial points.Sometimes when you are preparing a display window for printing, you plot

a solution curve you wish were not there. In the Edit menu there are severalcommands which allow you to erase items in the dfield7 Display window.In addition to those we have already explained, there are Edit!Erase allsolutions and Edit!Erase all graphics objects, which are self explanatory.The last item, Edit!Delete a graphics object, is much more �exible. Itwill allow you to delete individual solution curves, as well as text items andgraphs you have added to the window. Simply choose the option and selectthe object you wish to delete with the mouse.The dfield7 Display window is a standard MATLAB �gure window.

Therefore all of the standard editing commands are available. In particular,the commands xlabel, ylabel, and title can be used to change theseitems. To add text at arbitrary points in the dfield7 Display window,select Edit!Enter text on the Display Window, enter the desired text in theText entry dialog box, and then click the OK button. Use the mouse to clickat the lower left point of the position in the �gure window where you want

28

Page 29: Di⁄erential equations with MATLAB: an (advanced) introduction

the text to appear. It can easily happen that your placement of the text doesnot please you. If so, remove the text using Edit!Delete a graphics object,then try again.You can print or export the dfield7 Display window in a variety of

ways. However, the easiest way to print the �gure to the default printer is toclick the Print button in the dfield7 Display window. The Print and Quitbuttons and the message window will not be printed.Saving and Loading dfield7 Equation and Gallery Files. Suppose that

after entering all of the information into the dfield7 Setup window for yourexample, you decided to work on something else and come back to this ex-ample later. There are two ways to avoid the necessity of reentering thedata. The �rst method is temporary. The menu option Gallery!Add cur-rent equation to the gallery will do just that, after prompting you for a namefor the equation. When you are ready, you can choose this equation from theGallery menu, and all of the data will be entered automatically.However, if you have to quit dfield7, the new entry will no longer be

there when you come back. For this situation you can use the commandFile!Save the current equation. This option allows you to record the infor-mation on the dfield7 Setup window in a �le. Executing this option willbring up a standard �le save menu, where you are given the option of savingthe �le with a �lename and in a directory of your own choice. The �le willbe saved with the su¢ x .dfs. (It is not necessary to enter .dfs.) It can laterbe loaded back into dfield7 using the command File!Load an equation.It is also possible to save and load entire galleries using the appropriate

commands on the File menu. Gallery �les have the su¢ x .dfg. There is alsoa command that will delete the entire gallery, allowing you to start to build agallery entirely your own, and another command that will reload the defaultgallery, if that is what you want.Always wait until the word �Ready� appears in the dfield7 message

window before you try to do anything else with dfield7 or MATLAB. Whenyou want to quit dfield7, the best way is to use the Quit buttons found onthe dfield7 Setup or on the dfield7 Display windows. Either of these willclose all of the dfield7 windows in an orderly manner, and it will delete thetemporary �les that dfield7 creates in order to do its business.Plotting Several Solutions at Once. Dfield7 allows you to plot several

solutions at once. Select Options!Plot several solutions and note that themouse cursor changes to �cross-hairs� when positioned over the direction�eld. Select several initial conditions for your solutions by clicking the mouse

29

Page 30: Di⁄erential equations with MATLAB: an (advanced) introduction

button at several di¤erent locations in the direction �eld. When you are�nished selecting initial conditions, position the mouse cross-hairs over thedirection �eld and press the Enter or Return key on your keyboard. Solutiontrajectories will emanate from the initial conditions you selected with themouse.

4.3 PPLANE7

The MATLAB function pplane7 makes visualization of phase portraits forplanar systems of di¤erential equations easy. The functionality of pplane7is very similar to that of dfield7, so if you are familiar with dfield7, youwill have no trouble with pplane7. To see it in action, enter pplane7 at theMATLAB prompt. A new window will appear with the label pplane7 Setup.You will notice that there is a rather complicated autonomous system

already entered in the upper part of the pplane7 Setup window. There isa middle section for entering parameters and expressions, although none areentered at the moment. There is another section for describing a �displaywindow,�and yet another for de�ning what kind of �eld is to be used. Thereare three buttons at the bottom of the window and several menus across thetop. These are the same buttons and menus that are found in the pplane7Setup window and they work in pplane7 just as they do in dfield7. Clickthe button labeled Proceed. After a few seconds another window will open,this one labeled pplane7 Display.There are two buttons on the pplane7 Display window with the labels

Quit and Print. There are several menus. Finally, below the vector �eld thereis a small Cursor position window, and a larger message window throughwhich pplane will communicate with the user. At this time it should containthe single word �Ready,�indicating that it is ready to follow orders.To compute and plot a solution curve from an initial point, move the

mouse to that point, using the cursor position window to improve your accu-racy, and click the mouse button. The solution will be computed and plotted,�rst in the direction in which the independent variable is increasing, and thenin the opposite direction.If you open the Options menu, you will see several ways of modifying

how solutions are computed and plotted. The solution direction can be cho-sen by choosing Options!Solution direction!Forward or Options!Solutiondirection!Back. Some times it is desirable to indicate where the com-putation of a solution curve is started. This can be e¤ected by selecting

30

Page 31: Di⁄erential equations with MATLAB: an (advanced) introduction

Options!Mark initial points. In the Edit menu you will �nd the same �zoomin�and �zoom back�options available in dfield7.Just as in dfield7, zooming can be done with the mouse. For example,

if you have a two button mouse, you can zoom at a point by clicking anddragging with the right mouse button. There is an additional zoom option,Zoom in square.You can print the pplane7 Display window to the default printer without

the buttons and the message window by simply clicking the Print button.All of the print, save, and export options that are available for MATLAB�gure windows are also available for the pplane7 Display window. SelectOptions!Mark initial points to mark the initial points of our solution curves.Select Solutions!Keyboard input and start a solution trajectory with se-lected initial conditions. Note that this option behaves in a manner similarto that in dfield7.Although the phase plane solutions produced by pplane7 are useful, we

get a better understanding of a solution by looking at other graphical rep-resentations. This is easy to do in pplane7. Clicking on the Graph menureveals �ve choices. Select Graph!Both. Notice that the vector �eld inthe pplane7 Display window disappears and your cursor changes to a �crosshairs�as you move it over the �gure. Center the cross hairs on the solutiontrajectory and click the (left) mouse button. This action should produce aplot in a new pplane7 t-plot window. Both components of the solution areplotted against the independent variable t: In addition, the �gure contains alegend identifying the two curves, and radio buttons that enable easy selec-tion of �ve di¤erent views of the solution. These are the same options thatappear in the Graph menu.The most interesting of the plot options is the Composite plot. Click on

that radio button, and you get a 3-dimensional plot of both components ofthe solution versus t: However, it also contains the other views as projectionsonto the three coordinate planes. The composite plot lets you understandhow the various graphical representations are related. The composite and 3Dviews can be rotated so you can see them from di¤erent perspectives. SelectView!Figure Toolbar to bring up the toolbar. Then select the rotate tool,the icon on the far right of the toolbar. Now click and drag in the �gurewindow to rotate the view.The pplane7 Display window provides several editing commands that

are similar to those in the dfield7 Display window. In fact, there are afew more because of the additional features in pplane7. In particular, you

31

Page 32: Di⁄erential equations with MATLAB: an (advanced) introduction

can delete any graphics object, including text, by selecting Edit!Delete agraphics object and clicking on the object you wish to delete. The pplane7Display and t-plot �gure windows can be edited just like any MATLAB �gurewindow. However, use the property editors with caution, since they interferewith the interactive features of pplane7. The use of the rotate feature is anexception to this rule.You can print or export the pplane7 windows in the standard ways. The

Print buttons on the pplane7 Display and t-plot windows will cause the�gure to be printed to the default printer without the various buttons.As is the case for dfield7, the information on the setup window can be

added to the Gallery menu, and can be saved in �les. The �les containinginformation about systems have the su¢ x .pps. You can also make, save, andload entirely new galleries that contain a number of important systems for alecture or presentation. Gallery �les have the su¢ x .ppg. The mechanismsfor working with systems and galleries are the same as explained in theprevious section for dfield7.Pplane7 has also more advanced features such as drawing nullclines, �nd-

ing and classifying equilibrium points, displaying linearizations, and drawingthe separatrices that accompany saddle points. To sketch nullclines, selectedthe Nullclines option. Click the Proceed button to transfer information tothe pplane7 Display window. Use your mouse and click the phase plane inseveral locations to start solution trajectories.Return to the Setup window, select the Arrows option, and then click Pro-

ceed. This will remove the nullclines from the Display window and add thevector �eld. Next select Solutions!Show nullclines in the Display window,and the nullclines will be plotted on top of the vector �eld.Pplane7 can also be used to �nd equilibrium points. Select the Nullclines

for the direction �eld, click Proceed, then start a few trajectories by clickingthe mouse in the phase plane. Select Solutions!Find an equilibrium point,then move the mouse �cross hairs�near the intersection of the nullclines andclick the mouse. Pplane7 will plot the equilibrium point. Pplane7 also opensthe pplane7 Equilibrium point data window, which summarizes a number ofimportant facts about the equilibrium point including its classi�cation andlocation. Click the Go Away button to close the window.Select Gallery!linear system from the pplane7 Setup menu. Notice that

most of the work regarding classi�cation of critical points has been done foryou. All you have to do is adjust the parameters A, B, C, and D. Enteryour values of parameters for A, B, C, and D in the pplane7 Setup window,

32

Page 33: Di⁄erential equations with MATLAB: an (advanced) introduction

then click Proceed to transfer information to the pplane7 Display window.Select Solutions!Keyboard input and start a solution trajectory with initialcondition of your choice.Select Solutions!Find an equilibrium point and click your mouse near

the origin in the phase plane. Carefully examine the information provided inthe pplane7 Equilibrium point data window. Once you�ve found all of theequilibrium points, you can obtain a summary of the equilibrium points youfound by selecting Solutions!List computed equilibrium points. A summaryof the computed equilibrium points will be printed in the MATLAB commandwindow.Click the Display the linearization button to show the linear approxima-

tion for your nonlinear system. If we want to compare the nonlinear systemand its linearization, we should zoom in near the equilibrium point for thenonlinear system. Notice that the default linearization window is square, andthat both variables range from -1 to 1. In other words, the scales are thesame on each axis. When you zoom in the usual way using Edit!Zoom inthe pplane7 Display window, it is highly unlikely that the scales will be thesame on the two axes. However, if you choose Edit!Zoom in square, youautomatically get a new window with the same scale on the two axes. Aftermaking the menu selection, click the (left) mouse button on the equilibriumpoint is the Display window and drag a small rectangle. There are moreadvanced options in pplane7 to explore, try them if you are interested.

4.4 ODESOLVE

The MATLAB function odesolve provides a way to use MATLAB�s solverswith a graphical user interface. It can be applied to any system of �rst orderequations, and therefore to any system of any order. The dimension of thesystem is limited only by the size of the computer screen. Since it has agraphical interface, it is relatively easy to use, but the interface does presentlimitations as well. The interface of odesolve is very similar to those foundin d�eld and pplane. To begin, execute

>> odesolve

at the MATLAB prompt. This opens the odesolve Setup window. The sim-ilarities with dfield and pplane are clear. However, there are di¤erences aswell. One of the most important is the edit box for the number of equations.Change this number to 20 and depress the Tab or Enter key. The setup

33

Page 34: Di⁄erential equations with MATLAB: an (advanced) introduction

window expands to allow the entry of 20 equations and the correspondinginitial conditions. Near the bottom of the setup window, we see that ode45is the solver that will be used. This can be changed to any of the MATLABsolvers using the popup menu. We are also told that the output will be allvariables plotted against t: This can also be changed using the popup menu.To start a solution, click on the button Solve in a new window. After a

few seconds, we get a plot of all components of the solution to your systemof di¤erential equations plotted against t: Even with the legend, this �gureis a little busy. Go back to the setup window and select time plot from theoutput popup menu. Do so even though it looks like it is already selected. Inthe little window that appears, select only x and y; and then click Change.Click on Solve in a new window again. Experiment with other outputs. Thephase plane plot of y versus x is very interesting, as are some of the otherchoices. Experiment with the use of the other solvers. Change the initialconditions and the parameters.The Gallery menu contains several interesting systems. Experiment with

these to learn more about how odesolve works. If you are wondering aboutsti¤ equations, choose the 1D sti¤ example. Try to solve using ode45. Clickthe Stop button when you are tired of waiting. Then solve using ode15s.If you �nd it di¢ cult to see where a solution curve starts, choose the

option to mark initial points. You can also choose to mark all of the pointscomputed by the solver. Since odesolve has a limited number of outputpossibilities, it will sometimes be necessary to have access to the solutiondata. There are two ways of doing this using odesolve. First, you cancompute a solution using odesolve and export the data to the commandwindow workspace. The data in the command window will be a structurewith the name odedata*, where * is a small number chosen to not con�ictwith previously saved data. The structure will have a �eld for each variable.The second method is to export an ODE function m-�le, which can be usedwith any of MATLAB�s solvers to �nd numerical solutions. If you choosethis option, you will be asked for a �lename. If you then execute help on this�le, you will be given instructions on how to use a solver with this �le.There will be times when you will want to give a solver a smaller tolerance,

or change some other solver setting. This is possible in odesolve by selectingOptions!Solver settings. In this window it is possible to change settings forthe solvers which we have not discussed in this chapter. Read the MATLABdocumentation for the de�nitions.Finally, odesolve has the capability to save and load systems and whole

34

Page 35: Di⁄erential equations with MATLAB: an (advanced) introduction

galleries. These options are accessed from the File menu. They work like thesame options in dfield and pplane.

References

[1] B. Barnes and G.R. Fulford, Mathematical Modeling with Case Studies,2nd edition, CRC Press, Boca Raton - London - New York, 2009.

[2] R. Oakley and C. Ksir, Drugs, Society and Human Behaviour, 6th edition,McGraw-Hill, New York, 1993.

[3] J.C. Polking and D. Arnold, Ordinary Di¤erential Equations Using MAT-LAB, 3rd edition, Prentice Hall, 2003.

Have fun with ODEs in MATLAB!

35

Page 36: Di⁄erential equations with MATLAB: an (advanced) introduction

­3 ­2 ­1 0 1 2 3­3

­2

­1

0

1

2

3

y1

y2

Limit cycle for van der Pol equation for mu=1

Figure 17: Phase portrait for the van der Pol equation, � = 1:

36