Sunteți pe pagina 1din 26

CL MATCONTL: a continuation toolbox for

large equilibrium problems in MATLAB.


David Bindel∗ Mark Friedman† Willy Govaerts‡
Jeremy Hughes§ Yuri A. Kuznetsov¶
September 2008

Abstract
CL MATCONT and its GUI version MATCONT are MATLAB pack-
ages for the study of dynamical systems and their bifurcations for small
and moderate size problems. CL MATCONTL is an extension of the
functionality of CL MATCONT to large-scale computations of equilibria
bifurcations, via subspace reduction. It allows to compute curves of equi-
libria, limit points, Hopf points, and branch switching. CL MATCONTL
can also monitor user - defined functions and locate their roots along com-
puted curves. It can compute all necessary derivatives by finite differences,
from file or by using the symbolic toolbox of MATLAB.
In this tutorial we describe a numerical study of a finite difference
discretization of the 1-D Brusselator, a well known model system for au-
tocatalytic chemical reactions with diffusion. Most of the capabilities of
CL MATCONTL are illustrated.

Contents
1 Introduction. 2

1.1 Overview of Capabilities. . . . . . . . . . . . . . . . . . . . . . . 2


1.2 Installation and Initialization. . . . . . . . . . . . . . . . . . . . . 4
1.3 User-Supplied Files. . . . . . . . . . . . . . . . . . . . . . . . . . 4
∗ Courant Institute of Mathematical Sciences, New York University.
† Mathematical Sciences Department, University of Alabama in Huntsville, Huntsville, AL
35899. The author was supported in part under NSF DMS-0209536 and NSF ATM-0417774.
‡ Department of Applied Mathematics and Computer Science, Ghent University, Krijgslaan

281-S9, B-9000 Ghent, Belgium.


§ Mathematical Sciences Department, University of Alabama in Huntsville, Huntsville, AL

35899. The author was supported in part under NSF DMS-0209536 and NSF ATM-0417774.
¶ Mathematisch Instituut Budapestlaan 6, 3584CD Utrecht, The Netherlands.

1
2 bruss 1d1, bruss 1d2: Tutorial Demos, 1-D Brusselator. 5
2.1 Tutorial Demo: bruss 1d1. . . . . . . . . . . . . . . . . . . . . . 6
2.1.1 Copying the demo files. . . . . . . . . . . . . . . . . . . . 6
2.1.2 Continuation of equilibrium: testbruss BP0, testbruss LP0. 6
2.1.3 Continuation of fold points: testbruss LP1. . . . . . . . 8
2.1.4 Restarting at a user point: testbruss U0, testbruss U1. 8
2.1.5 Switching a branch: testbruss BP1. . . . . . . . . . . . . 10
2.2 Tutorial Demo: bruss 1d2. . . . . . . . . . . . . . . . . . . . . . 13

2.2.1 Copying the demo files. . . . . . . . . . . . . . . . . . . . 13


2.2.2 Continuation of Hopf points: testbruss HP0, testbruss HP1. 13

3 Problem definition m-file 14


3.1 init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.2 fun eval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.3 jacobian (Optional) . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.4 jacobianp (Optional) . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.5 Usernorm (Optional) . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.6 User Functions (Optional) . . . . . . . . . . . . . . . . . . . . . . 17
3.7 M-file: bruss 1d1.m . . . . . . . . . . . . . . . . . . . . . . . . . . 18

4 Options. 20

5 Testrun Script files 23


5.1 run continuer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.2 plotL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
5.3 saveSingPoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
5.4 User Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

1 Introduction.

1.1 Overview of Capabilities.


Consider a parametrized dynamical system defined as a set of ODEs of the form
du
= f (u, α), f (u, α), u ∈ Rn , (1)
dt
where α denotes one or more free parameters. The aim of CL MATCONTL
is to provide a continuation environment in MATLAB for branches of large
stationary problems
f (x) ≡ f (u, α) = 0, (2)
which is compatible with the standard in the MATLAB ODE representation
of differential equations. A typical example comes from a spatial discretization
of elliptic partial differential equations, in which case fu will typically be large

2
and sparse. In this case, an invariant subspace R(s) corresponding to a few
eigenvalues near the imaginary axis provides information about stability and
bifurcations.
CL MATCONT [7] and its GUI version MATCONT [6] are MATLAB pack-
ages for the study of dynamical systems and their bifurcations for small and
moderate size problems.
The CIS algorithm is an algorithm for computing a smooth orthonormal
basis for an invariant subspace R(s) of a parameter-dependent matrix A(s)
[5, 8, 11, 1], [2], [3]. This allows for computation and continuation of a much
smaller restriction C(s) := A(s)|R(s) of A(s) onto R(s). And C(s) provides the
relevant information about bifurcations.
We have incorporated the CIS algorithm (in this case A(x(s)) = fu (x(s)))
into CL MATCONT to extend its functionality to large-scale computations of
equilibria bifurcations, via subspace reduction, see [1], [4], [9], [3], [10], for
some initial results. This has resulted in a MATLAB bifurcation package
CL MATCONTL. This toolbox is developed with the following targets in mind:

• detection of singularities via test functions;


• singularity-specific location code;
• processing of regular and singular points;
• support of symbolic derivatives;
• support for sparse matrices.

The following actions are supported by the present version of CL MATCONTL:

• continuation of equilibria with respect to a control parameter;


• detection of fold, Hopf and branching points on curves of equilibria;
• computation of normal form coefficients for fold and Hopf equilibrium
bifurcations;
• continuation of fold and Hopf equilibrium bifurcations in two control pa-
rameters;
• detection of all codim 2 equilibrium bifurcations (cusp, Bogdanov-Takens,
generalized Hopf, zero-Hopf, and double Hopf) on fold and Hopf curves;
• computation of normal form coefficients for codim 2 equilibrium bifurca-
tions which include multi-linear forms of order up to 3;
• detection of branch bifurcation points on fold curves;
• branch switching at branch points of equilibria using 3 methods.

The following notation is used in the output in CL MATCONTL:

3
H a Hopf point on a curve of equilibria
BP a branch point on a curve of equilibria
LP a limit point on a curve of equilibria
BT a Bogdanov-Takens point on a curve of limit points or Hopf points
ZH a zero-Hopf point on a curve of limit points or Hopf points
CP a cusp point on a curve of limit points
BP a branch point on a curve of limit points
DH a double-Hopf point on a curve of Hopf points
GH a generalized Hopf, or Bautin point on a curve of Hopf points
a the normal form coefficient of a limit point
We assume that the reader is familiar with dynamical systems theory and
knows about equilibria, Hopf points, etc., [12], [13]. We also assume an ele-
mentary knowledge of MATLAB but do not assume familiarity with numerical
methods.

1.2 Installation and Initialization.


The current version of the package is freely available for download at:
http://webpages.uah.edu/˜hughesjs/.
It requires MATLAB 7.* to be installed on your computer. Installation of
CL MATCONTL is simple. Downloading and unzipping the CL MATCONTL
package in the MATLAB ’work’ directory creates a directory ’CL MATCONTL’
on the computer. It contains init.m and ReadMe.txt files, as well as a number
of subdirectories.
We start CL MATCONTL by changing to the ’CL MATCONTL’ directory
and typing ’init’ on the MATLAB command line. The init.m file registers
the directories with MATLAB and compiles any .mex files if necessary. If mex
files have never been compiled on your machine, MATLAB may prompt you
to select a compiler for .mex files. You must run init.m each time you open
MATLAB when you wish to use CL MATCONTL.

1.3 User-Supplied Files.


The user must prepare the following two m-files.
The problem definition m-file (see Section 3) contains functions that define
a particular problem, including the function f in equation (2), the symbolic
Jacobian matrix, etc.
The testrun script (see Section 5) contains the initial parameters for the
problem, the options to be used, and the code that executes continuation.
The above two files are located in the problem diectory, see e.g. /Tutorial/bruss 1d1/bruss 1d1
and /Tutorial/bruss 1d1/testbruss BP0.

4
2 bruss 1d1, bruss 1d2: Tutorial Demos, 1-D Brus-
selator.
The 1D Brusselator is a well known model system, intended to model the
Belusov - Zhabotinsky reaction, for autocatalytic chemical reactions with diffu-
sion:

d1 00 d2 00
l2 u − (b + 1)u + u2 v + a = 0, l2 v + bu − u2 v = 0, in Ω = (0, 1),
(3)
u(0) = u(1) = a, v(0) = v(1) = ab .

This problem exhibits a rich bifurcation scenario and has been used in the litera-
ture as a standard model for bifurcation analysis. The approximate equilibrium
nonconstant solution is:
½
u(x) = a + 2 sin(πx)
(4)
v(x) = ab − 12 sin(πx).

The initial values of the parameters are: a = 2, b = 4.6, d1 = 0.0016, d2 = 0.08


and l = 0.06. The initial solution (4) is not an equilibrium, but the continuer
will try to converge to an equilibrium close to the initial solution.
We use a finite difference approximation with equidistant meshes to generate
a system of algebraic equations. To avoid spurious solutions (solutions that are
induced by the discretization but do not actually correspond to solutions of the
undiscretized problem), one can vary the number of mesh points by setting the
parameter N . In this demo we use N = 500, hence the size of the system (2)
is n = 1000. If the same solution is found for several discretizations, then we
can assume that they correspond to solutions of the continuous problem. The
Jacobian is a sparse 5-band matrix. In the ode-file bruss 1d1.m describing the
problem (see Section 3.7) the Jacobian is introduced as a sparse matrix.

Adding Your Own Examples. User examples can be added by creating


a directory in the /User directory that contains a problem definition file and
at least one test run. The directory should also contain /data and /logs
subdirectories. For MATLAB to make use of any of the subfolders of this
directory you must also add them to the path using the addpath(...) function.
Init.m will add all the subdirectories of /User to the path as well as their /data
and /logs subdirectories when it is run. If you are having trouble getting a
new example to work, try running init.m first.

Running all the demos in sequence: rundemos. One can run all the demos
in sequence using a script to rundemos.m located in the /Testruns directory.
The text output from that script is saved in the file demos in the /Testruns
directory.

5
2.1 Tutorial Demo: bruss 1d1.
2.1.1 Copying the demo files.
Assume, you are in the ’CL MATCONTL’ directory

1. Copy the directory /Tutorial/bruss 1d1 into the directory /User.


2. Open init.m and enter the following lines below the line % add User
problems————————————–:
addpath([cd ’/User/’]);
addpath([cd ’/User/bruss 1d1/’]);
addpath([cd ’/User/bruss 1d1/logs/’]);
addpath([cd ’/User/bruss 1d1/data/’]);

2.1.2 Continuation of equilibrium: testbruss BP0, testbruss LP0.


We are interested in an equilibrium solution u to the system (2) and its depen-
dence on the parameter l. The following notation is used in the output: x =
(u, l) ∈ Rn+1 . We perform continuation by running the test file testbruss BP0
(see Section 5). The file testbruss BP0 is located in the /Tutorial/bruss 1d1
directory. This produces the following output and figure 1:
>> testbruss BP0
First point found: u = (+2.012259e+000,...,+2.296933e+000)
Active parameters = [+6.228439e-002 ]
tangent vector to first point found
Step 11: Singularity 1 detected ...
Branch Angle = 0.500000 * pi
BP located: u = (+2.000000e+000,...,+2.300000e+000)
Active parameters = [+7.984418e-002 ]
Step 65: Singularity 1 detected ...
Branch Angle = 0.500000 * pi
BP located: u = (+1.991792e+000,...,+2.307979e+000)
Active parameters = [+2.499571e-001 ]
Step 70: Singularity 3 detected ...
LP located: u = (+1.993795e+000,...,+2.307016e+000)
Active parameters = [+2.526672e-001 ]
Lyupanov Coefficient = -7.192281e+001
Step 95: Singularity 1 detected ...
Branch Angle = 0.500000 * pi
BP located: u = (+2.000000e+000,...,+2.300000e+000)
Active parameters = [+2.211210e-001 ]
Step 109: Singularity 1 detected ...
Branch Angle = 0.500000 * pi
BP located: u = (+2.012524e+000,...,+2.294044e+000)
Active parameters = [+1.698318e-001 ]

6
0.26
BPLP

0.24
BP
0.22

0.2

0.18
BP

0.16

0.14

0.12

0.1
BP
0.08
LP
0.06
1.98 1.99 2 2.01 2.02 2.03 2.04

Figure 1: Continuation of equilibrium points.

Step 176: Singularity 3 detected ...


LP located: u = (+2.018575e+000,...,+2.295407e+000)
Active parameters = [+6.063973e-002 ]
Lyupanov Coefficient = 1.095254e+003
Closed curve detected at step 205
Last Point Found: u = (+2.012259e+000,...,+2.296933e+000)
Active parameters = [+6.228439e-002 ]
elapsed time = 39.5 secs
Number of Points in curve = 205
Along the equilibrium curve, at Step 173 LP is located for parameter l =
0.06064. We modify testbruss BP0 by changing the continuation direction in
to create testbruss LP0.m. This produces the following output:
>> testbruss LP0
First point found: u = (+2.012259e+000,...,+2.296933e+000)
Active parameters = [+6.228439e-002 ]

7
tangent vector to first point found
Step 23: Singularity 3 detected ...
LP located: u = (+2.018576e+000,...,+2.295406e+000)
Active parameters = [+6.063973e-002 ]
Lyupanov Coefficient = 4.902650e+002
Last Point Found: u = (+2.020614e+000,...,+2.294900e+000)
Active parameters = [+6.081415e-002 ]
elapsed time = 8.8 secs
Number of Points in curve = 50

2.1.3 Continuation of fold points: testbruss LP1.


We restart at LP, computed at Step 5 of testbruss LP0 run, and compute a
curve of folds in two control parameters (l, a). The following notation is used in
the output: x = (u, l, a) ∈ Rn+2 . We perform continuation by running the test
file testbruss LP1. This produces the output below, while figure 2 is produced
by the combination of the testbruss LP0 and testbruss LP1 runs:
>> testbruss LP1
First point found: u = (+2.018569e+000,...,+2.295414e+000)
Active parameters = [+6.063942e-002 +1.999993e+000 ]
tangent vector to first point found
Last Point Found: u = (+2.011398e+000,...,+2.303918e+000)
Active parameters = [+6.028899e-002 +1.992583e+000 ]
elapsed time = 34.9 secs
Number of Points in curve = 50

2.1.4 Restarting at a user point: testbruss U0, testbruss U1.


A user point is defined by a user function in a problem definition m-file. Once
a user point is located and saved, it can be used as the starting point for con-
tinuation of another curve. The two consecutive test runs testbruss U0 and
testbruss U1produce the following output and figure 3.
>> testbruss U0
First point found: u = (+2.047607e+000,...,+2.288090e+000)
Active parameters = [+6.228294e-002 ]
tangent vector to first point found
Step 9: Singularity 3 detected ...
LP located: u = (+2.072138e+000,...,+2.282161e+000)
Active parameters = [+6.063833e-002 ]
Lyupanov Coefficient = 6.523453e+002
Step 48: User Function 1 detected ...
Step 48: User Function 1: "u1" located: u = (+2.107945e+000,...,+2.272710e+000)
Active parameters = [+6.497876e-002 ]
Last Point Found: u = (+2.112461e+000,...,+2.271329e+000)
Active parameters = [+6.650598e-002 ]
elapsed time = 4.9 secs

8
2.304

2.303

2.302

2.301

2.3

2.299

2.298

2.297

2.296
LP
2.295

2.294
2.011 2.012 2.013 2.014 2.015 2.016 2.017 2.018 2.019 2.02

Figure 2: Continuation of equilibrium points (the lower branch) and continua-


tion of fold points (the upper branch).

9
6.5
u1

5.5

LP
5

4.5

4
2.2 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29

Figure 3: Restarting at a user point.

Number of Points in curve = 50


>> testbruss U1
First point found: u = (+2.107945e+000,...,+2.272710e+000)
Active parameters = [+2.000000e+000 ]
tangent vector to first point found
Last Point Found: u = (+2.148661e+000,...,+2.202851e+000)
Active parameters = [+2.069284e+000 ]
elapsed time = 1.6 secs
Number of Points in curve = 15

2.1.5 Switching a branch: testbruss BP1.


When a branch point is located, CL MATCONTL attempts to compute a tan-
gent vector to the second branch. If successful, CL MATCONTL can then

10
switch to the second branch and perform its continuation. The branch point
data can be obtained in one of three ways:

1. Calculating the normal form coefficients and then finding a tangent vector
to the second branch by using the algebraic branching equation (ABE).
2. Finding an orthogonal vector to the tangent vector to the first branch,
in the Null space of the Jacobian at the branch point, and using it as an
initial guess for a tangent vector to the second branch.
3. A bisection-like procedure, which is an improved version of 2.

We restart at BP, computed at Step 22 of tesrbruss BP0 run, switch to the


second branch and perform its continuation by running the test file testbruss BP1.
This produces the output below, while figure 4 is produced by the combination
of the tesrbruss BP0 and testbruss BP1 runs (modified with MATLAB for
this presentation):
>> testbruss BP1
First point found: u = (+1.991394e+000,...,+2.307827e+000)
Active parameters = [+2.498388e-001 ]
tangent vector to first point found
Step 1: Singularity 1 detected ...
Branch Angle = 0.500000 * pi
BP located: u = (+1.991792e+000,...,+2.307979e+000)
Active parameters = [+2.499571e-001 ]
Step 52: Singularity 1 detected ...
Branch Angle = 0.500000 * pi
BP located: u = (+2.000000e+000,...,+2.300000e+000)
Active parameters = [+1.597067e-001 ]
Closed curve detected at step 108
Last Point Found: u = (+1.991394e+000,...,+2.307827e+000)
Active parameters = [+2.498388e-001 ]
elapsed time = 19.0 secs
Number of Points in curve = 108

Remark 1 In the tesrbruss BP0 run, the data for the run was saved using the
command:

s = saveSingPoints(’testbruss Branch’,s,p,ap1);
The data is then loaded in tesrbruss BP1, and the following lines are used
to perform continuation along the second branch.
load testbrussBranch s;
data = s(3);
ap1 = data.ap;
[s,filename] = run continuer(@bruss 1d1, @equilibriumL, data.p, ap1,
opt, data);

11
0.26
BPLP
0.25
0.24
BP
0.22

0.2

0.18
BP
BP
0.16
L

0.14

0.12

0.1

BP
0.08
LP
0.06

1.98 1.99 2 2.01 2.02 2.03 2.04


x1

Figure 4: Switching a branch: the first branch of equilibria and the second
branch.

12
2.2 Tutorial Demo: bruss 1d2.

2.2.1 Copying the demo files.


Assume, you are in the ’CL MATCONTL’ directory

1. Copy the directory /Tutorial/bruss 1d2 into the directory /User.


2. Open init.m and enter the following lines below the line % add User
problems————————————–:
addpath([cd ’/User/bruss 1d2/’]);
addpath([cd ’/User/bruss 1d2/logs/’]);
addpath([cd ’/User/bruss 1d2/data/’]);

2.2.2 Continuation of Hopf points: testbruss HP0, testbruss HP1.


The system (2) also has a constant equilibrium solution u(x) = a, v(x) =
b/a. We continue this constant solution with respect to parameter b using
testbruss HP0 and locate, in particular, a Hopf point. We restart at H, com-
puted at Step 18 of testbruss HP0 run, and compute a curve of Hopf points
in two control parameters (a, b) using testbruss HP1. These two consecutive
test runs produce the following output and figures 5 and 6, correspondingly:
>> testbruss HP0
First point found: u = (+4.000000e+000,...,+4.275000e+000)
Active parameters = [+1.710000e+001 ]
tangent vector to first point found
Step 4: Singularity 2 detected ...
H located: u = (+4.000000e+000,...,+4.301403e+000)
Active parameters = [+1.720561e+001 ]
Lyapunov Coefficient = 7.114196e-003
Last Point Found: u = (+4.000000e+000,...,+4.329433e+000)
Active parameters = [+1.731773e+001 ]
elapsed time = 3.0 secs
Number of Points in curve = 10
>> testbruss HP1
First point found: u = (+4.000000e+000,...,+4.301403e+000)
Active parameters = [+1.720561e+001 +1.000000e+000 ]
tangent vector to first point found
Step 1: Singularity 3 detected ...
label = DH located: u=(+4.000000e+000,...,+4.301463e+000)
Active parameters = [ +1.720585e+001 +1.003494e+000]
Neutral saddle
Step 20: Singularity 2 detected ...
Problems Locating Sigularity
Step 51: Singularity 3 detected ...

13
label = DH located: u=(+4.000000e+000,...,+4.302080e+000)
Active parameters = [ +1.720832e+001 +1.039496e+000]
Neutral saddle
Step 73: Singularity 3 detected ...
label = DH located: u=(+4.000000e+000,...,+4.302250e+000)
Active parameters = [ +1.720900e+001 +1.049407e+000]
Neutral saddle
Step 96: Singularity 3 detected ...
label = DH located: u=(+4.000000e+000,...,+4.302539e+000)
Active parameters = [ +1.721015e+001 +1.066266e+000]
Neutral saddle
Last Point Found: u = (+4.000000e+000,...,+4.302539e+000)
Active parameters = [+1.721016e+001 +1.066282e+000 ]
elapsed time = 159.2 secs
Number of Points in curve = 100

3 Problem definition m-file


The problem definition m-file is the file used to specify the functions to be
used for a particular problem. There are 3 required and 3 optional functions in
the m-file. The first function returns a list of function handles to point to the
remaining functions in the file. As an example, consider the bruss 1d1.m file
(see Section 3.7). Its primary function is:
function out = bruss 1d1
out{1} = @init;
out{2} = @fun eval;
out{3} = @jacobian;
out{4} = [];%@jacobianp;
out{5} = @usernorm;
out{6} = @user1;
The commented out jacobianp for out{4} means that the function is not
used for this problem.
The line, handles = feval(@bruss 1d1);, gets the function handles for
this problem definition file.
The individual functions are described below. Each function has a specific
input and output syntax that must be followed for CL MATCONTL to be able
to use the functions. This is important to remember when creating your own
problem definition m-files.

3.1 init
[tspan,y0,options] = init(p1 , ..., pn )
init is the first function handle defined in the primary function. It takes
the full list of parameters that are being used for the problem. It must return

14
17.35

17.3

17.25

H
17.2

17.15

17.1
3 3.5 4 4.5 5

Figure 5: Continuation of a constant equilibrium solution.

15
17.2105
DH
17.21

17.2095
DH
17.209

17.2085 DH

17.208

17.2075

17.207

17.2065

17.206 DH

17.2055
3 3.5 4 4.5 5

Figure 6: Continuation of a curve of Hopf Points

16
the value for y0, but the values tspan and options can be empty. This is the
starting point for continuation.

3.2 fun eval


d×dt = fun eval(t, x, p1 , ..., pn )
The function fun eval takes a scalar t, a vector x, and the full parameter list
used for the problem. It returns the vector dxdt. This notation is used to reflect
the nature of the non-linear problem x0 = f (t, x, p1 , ..., pn ). An equilibrium
solution is one where f (t, x, p1 , ..., pn ) = 0 for all t. For most problems t is not
used.
The function fun eval must be the second function handle returned by the
primary function.

3.3 jacobian (Optional)


dfdx = jacobian(t, x, p1 , ..., pn )
The jacobian function takes a scalar t, a vector x, and the full parameter
list used for the problem. It returns the jacobian matrix dfdx.
If the jacobian function is not defined or not being used, the third function
handle returned by the primary function must be empty.

3.4 jacobianp (Optional)


dfdp = jacobianp(t, x, p1 , ..., pn )
The parameter jacobian function jacobianp takes a scalar t, a vector x,
and the full parameter list used for the problem. It returns the matrix dfdp.
If the jacobianp function is not defined or not being used, the fourth func-
tion handle returned by the primary function must be empty.

3.5 Usernorm (Optional)


normuser = usernorm(arg)
The usernorm function takes a vector arg and returns a real number. The
function has all the properties of a norm. It is used to approximate function
norms for ODE and PDE problems.
If the usernorm function is not defined or not being used, the fifth function
handle returned by the primary function must be empty.

3.6 User Functions (Optional)


All remaining function handles are assumed to be User Functions. User func-
tions should take the same inputs as fun eval and return a real number.

17
3.7 M-file: bruss 1d1.m
This is the file used for all examples in this tutorial.
function out = bruss 1d1
%
% Odefile of 1-d Brusselator model
% This file uses a non-constant approximate solution as a starting
guess.
out{1} = @init;
out{2} = @fun eval;
out{3} = @jacobian;
out{4} = [];%@jacobianp;
out{5} = @usernorm;
out{6} = @user1;
% ----------------------------------------------------------------------
function dxdt = fun eval(t,x,N,L,A,B,Dx,Dy)
y = x(N+1:2*N);
x(N+1:2*N) =[];
x0 = A; x1 = A;
y0 = B/A; y1 = B/A;
L2 = L^2;
h = 1/(N+1);
cx = (Dx/L2)/(h*h);
cy = (Dy/L2)/(h*h);
dxdt = zeros(N,1);
dydt = zeros(N,1);
dxdt(1) = (x0-2*x(1)+x(2))*cx + A - (B+1)*x(1) + x(1)*x(1)*y(1);
dxdt(N) = (x(N-1)-2*x(N)+x1)*cx + A - (B+1)*x(N) + x(N)*x(N)*y(N);
dydt(1) = (y0-2*y(1)+y(2))*cy + B*x(1) - x(1)*x(1)*y(1);
dydt(N) = (y(N-1)-2*y(N)+y1)*cy + B*x(N) - x(N)*x(N)*y(N);
i=2:N-1;
dxdt(i) = (x(i-1)-2*x(i)+x(i+1))*cx + A - (B+1)*x(i) + x(i).*x(i).*y(i);
dydt(i) = (y(i-1)-2*y(i)+y(i+1))*cy + B*x(i) - x(i).*x(i).*y(i);
dxdt = [dxdt; dydt];
% --------------------------------------------------------------------------
function [tspan,x0,options] = init(N,L,A,B,Dx,Dy)
tspan = [0; 10];
x0 = zeros(2*N,1);
i=1:N;
x0(i) = A + 2*sin(pi*i/(N+1));
x0(N+i) = B/A - 0.5*sin(pi*i/(N+1));
handles = feval(@bruss 1d1);
options = odeset(’Vectorized’,’on’, ’Jacobian’, handles(3));
% --------------------------------------------------------------------------
function dfdx = jacobian(t,x,N,L,A,B,Dx,Dy)
y = x(N+1:2*N);

18
x(N+1:2*N) =[];
x0 = A; x1 = A;
y0 = B/A; y1 = B/A;
L2 = L^2;
h = 1/(N+1);
cx = (Dx/L2)/(h*h);
cy = (Dy/L2)/(h*h);
% Sparse jacobian
A = zeros(2*N,3);
A(1:N-1,2)=cx;
A(1:N,3)=-2*cx -(B+1) + 2*x(1:N).*y(1:N);
A(1:N,4)=cx;
A(N+1:2*N,2) = cy;
A(N+1:2*N,3) = -2*cy -x(:).*x(:);
A(N+2:2*N,4) = cy;
A(1:N,1) = B - 2*x(:).*y(:);
A(N+1:2*N,5) = x(:).*x(:);
dfdx = spdiags(A, [-N,-1:1,N] , 2*N, 2*N);
% --------------------------------------------------------------------------
function dfdp = jacobianp(t,x,N,L,A,B,Dx,Dy)
y = x(N+1:2*N);
x(N+1:2*N) =[];
x0 = A; x1 = A;
y0 = B/A; y1 = B/A;
L2 = L^2;
h = 1/(N+1);
cx = (Dx/L2)/(h*h);
cy = (Dy/L2)/(h*h);
kx = (-2/L)*cx;
ky = (-2/L)*cy;
Sx = zeros(N,1);
Sy = zeros(N,1);
Sx(1) = kx*(x0-2*x(1)+x(2));
Sy(1) = ky*(y0-2*y(1)+y(2));
Sx(N) = kx*(x(N-1)-2*x(N)+x1);
Sy(N) = ky*(y(N-1)-2*y(N)+y1);
i=2:N-1;
Sx(i) = kx*(x(i-1)-2*x(i)+x(i+1));
Sy(i) = ky*(y(i-1)-2*y(i)+y(i+1));
dfdp = [ zeros(2*N,1) [Sx;Sy] ];
% -------------------------------------------------------------------------
function normuser = usernorm(arg)
n = length(arg);
normuser = sqrt(1/n)*norm(arg);
% -------------------------------------------------------------------------
function uf1 = user1(t,x,N,L,A,B,Dx,Dy)

19
uf1 = L - 6.5e-002;
% ---------------------------------------------------------------------

4 Options.
It is possible to specify various options. The continuer stores the handle to the
options in the variables contopts. A call to feval(cds.curve.options) must
return a structure created with contset:

options = contset();

will initialize the structure. Options can then be set using

options = contset(options, optionname, optionvalue);

where optionname is an option from the following list.


Cont SmoothingAngle

Cont MaxNumPoints maximum number of points on the curve (default:


300)
Cont Direction boolean indicating the direction of the continuation (sign of
the initial tangent vector) v0 (default: 0)
Cont CheckClosed number of points indicating when to start to check if the
curve is closed (0 = do not check) (default: 50)
Cont AdaptSteps number of points indicating when to adapt the problem
while computing the curve (default: 1=adapt always)
Cont SmoothingAngle Minimum allowed angle between tangent vectors at
π
adjacent points (default: 50 )
Cont Solver Name or function handle of the solver to be used (default: ”Moore-
Penrose”)
Cont InitStepsize the initial stepsize (default: 0.01)
Cont MinStepsize the minimum stepsize to compute the next point on the
curve (default: 10−5 )
Cont MaxStepsize the maximum stepsize (default: 0.1)
Cont MaxCorrIters maximum number of correction iterations (default: 10)
Cont MaxNewtonIters maximum number of Newton-Raphson iterations be-
fore switching to Newton-Chords in the corrector iterations (default: 3)
Cont FunTolerance tolerance of function values: ||F (x)|| ≤ FunTolerance is
the first convergence criterion of the Newton iteration (default: 10−6 )

20
Cont VarTolerance tolerance of coordinates: ||δx|| ≤ VarTolerance is the
second convergence criterion of the Newton iteration (default: 10−6 )
Cont IncrFinDiff the increment to compute the derivatives numerically (de-
fault: 10−5 )
Cont Singularities boolean indicating the presence of test functions and a
singularity matrix (default: 0)
Cont Testfunctions boolean indicating the presence of test functions and sin-
gularity matrix (default: 0)
Cont Eigenvalues boolean indicating the computation of the eigenvalues (de-
fault: 0)
Cont Userfunctions boolean indicating the presence of user functions (de-
fault: 0)
Cont UserFuncInfo is an array with structures containing information about
the userfunctions. This structure has the following fields:
.label label of the userfunction
.name name of this particular userfunction
.state boolean indicating whether the userfunction has to be evaluated or not

Cont LogFile Generate disgnostic log file in the .../Logs/ directory (default:
0)
Cont DiagnosticsLevel Diagnostic level changes the amount of information
written to screen/logfile, -inf to suppress all output ( default: 0 )

0: Standard Output Information about singularities and general infor-


mation about the curve will be displayed. Level 0 information is
always output to the screen when using a log-file.
1: Additional Information Eigenvalues near zero, the dimension of the
invariant subspace and unstable subspace (CIS)
2: Advanced information Convergence information on singularities. Ad-
ditional error messages concerning convergence of singularity locator
functions.
3: Maximal information Information concerning eigenvalues at singu-
larity points.
4: Developer information Custom messages for development of new
code. (Not intended for users)
5: Debugging Information function markers and other debugging in-
formation. (Not intended for users)

Loc UseLocators boolean vector indicating the user has provided his own
locator code to locate zeroes of test functions. Otherwise the default
locator will be used (default: empty)

21
Loc MaxIters Maximum iterations for the locator function (default: 5)
Loc MaxTestIters Maximum number of iterations to locate a zero of a test-
function (default: 10)
Loc TestTolerance Tolerance of test functions when used as a locator (de-
fault: 10−5 )
Loc VarTolerance Tolerance for variables used in locator function (default:
10−4 )
Loc FunTolerance Tolerance for residuals used in locator function (default:
10−5 )
Loc IgnoreSings vector containing indices of singularities which are to be
ignored (default: empty)
CIS usingCIS Choose whether to calculate subspace (default: 1 )
CIS AdaptOnOverlap Whether to adapt space on overlap or not? (default:
1)
CIS SparseSolvers Whether to use sparse solver or not? (default: 0 )
CIS InitNUnstable Number of initial unstable eigenvalues. A negative num-
ber forces contCIS to compute the number of unstable eigenvalues. (
default: −1 )
CIS NUnstableGuess Initial guess for the number of unstable eigenvalues. (
default: 15 )
CIS MaxUnstable Maximum number of the unstable eigenvalues. ( default:
40 )
CIS InitSubSize Initial Subspace Size (default:4)
CIS NStableRef The number of stable Reference Eigenvalues for CIS ( de-
fault: 4 )
CIS NExtra The number of extra eigenvalues to compute. This is used in
overlap detection. ( default: 4 )
Ric Euler Use Euler predictor in ricatti solvers (default: 1 )

Ric MaxNewtonIters Maximum allowed Newton steps in ricatti solvers (


default: 10 )
Ric FunTolerance Newton residual convergence tolerance in ricatti solvers (
default: 1e − 5 )
Ric VarTolerance Newton step convergence tolerance in ricatti solvers( de-
fault: 1e − 5 )

22
Ric Transform ricatti solver transformation (’none’/’invert’/’cayley’) (default:
’none’ )
Ric Cayley Shift Cayley transform shift parameter in ricatti solvers (default:
1)
Ric Select Method used to select subspace in ricatti solvers ( default: ’ric’ )
Ric Partial Q Keep only Q1 even in dense case in ricatti solvers (default: 0 )
EQ BranchingMethod Method used for branch switching (0,1,2) ( default:
0)
EQ SingLinSystTol Tolerance for singular linear system in equilibrium loca-
tors (default: 0.1)
TestPath This should always be present in any testrun and should always be
mfilename(’fullpath’). It is the full path the the test run file.

5 Testrun Script files


Test run script files contain all of the information required to run an example
in CL MATCONTL. The items that are needed in a testrun script are the
following:

Options The standard options and CIS options are set and stored in a structure
Continuation A call to run continuer(...) is made
Saving Data After continuation, data can be saved.
Here is an example of a testrun script m-file testbruss BP0.m:

opt = contset(); %Clear previous options


opt = contset(opt,’Cont LogFile’, 1);
opt = contset(opt,’Cont DiagnosticsLevel’, 3);
opt = contset(opt,’Cont MaxStepsize’, 3);
opt = contset(opt,’Cont InitStepsize’, 3);
opt = contset(opt,’Cont MinStepsize’, 1e-5);
opt = contset(opt,’Cont MaxCorrIters’, 12);
opt = contset(opt,’Cont MaxNewtonIters’, 15);
opt = contset(opt,’Cont FunTolerance’, 1e-4);
opt = contset(opt,’Cont VarTolerance’, 1e-4);
opt = contset(opt,’Cont Singularities’, 1);
opt = contset(opt,’Cont Userfunctions’, 0);
opt = contset(opt,’Cont MaxNumPoints’, 2000);
opt = contset(opt,’Cont SmoothingAngle’, pi()/30);
opt = contset(opt,’CIS SparseSolvers’, 1);
opt = contset(opt,’CIS NStableRef’, 4);

23
opt = contset(opt,’RIC Cayley Shift’, 10);
opt = contset(opt,’EQ BranchingMethod’, 2);
opt = contset(opt,’Loc UseLocators’, [1 1 1]);
opt = contset(opt,’TestPath’,mfilename(’fullpath’));
N = 500; L = 0.06; A = 2; B = 4.6; Dx = 0.0016; Dy = 0.008;
p = [N; L; A; B; Dx; Dy]; ap1 = 2;
[s,filename] = run continuer(@bruss 1d1, @equilibriumL, p, ap1, opt,[]);
plotL(filename,s,[1 2*N+1]);
s = saveSingPoints(’testbruss Branch’,s,p,ap1);

5.1 run continuer


The function run continuer takes the following inputs:
run continuer(PROBDEF, CURVEDEF, p, ap, opts, data)

PROBDEF The problem definition file to be used for continuation; this is user
supplied.
CURVEDEF The curve definition file to be used you can choose from the
following:

Equilibrium Curve @equilibriumL, used for equilibrium continuation


and branch switching
Hopf Curve @hopfL, used for continuation starting from a Hopf point
located on a curve of equilibria
Limit Point Curve @limitpointL, used for continuation starting from a
limit point located on a curve of equilibria

p The starting parameter list as defined in the problem definition m-file

ap The active parameter


opts (Optional) Standard options structure.
data (Optional) User supplied data assumed to be output from saveSingPoints
function

The function run continuer returns the signgularity sturcture s and name
of the data file where the data for that run is stored.

5.2 plotL
The function plotL takes the following inputs:
plotL(filename,s,plotaxes)

filename The name of the data file created by run continuer. It is stored in
the .../Data/(PROBDEF) directory.

24
s The singularities data structure returned by run continuer.
plotaxes A two or three diminsional row vector indicating which indices
are to be plotted.

5.3 saveSingPoints
This function saves the output singularities so they can be used by run continuer
to start the appropriate continuation.
saveSingPoints(’filename’,s,p,ap)
It saves data for branch, Hopf, fold, user, start, and end points and saves
them in filename.mat the data can be loaded using the command
load filename s
For continuation starting from a saved point, the correct point must be
chosen from the list of singularities saved in s; s(i).label contains a two
character label for the singularity that defines its type. These are the labels
for the singularities that saveSingPoints stores.
00 Starting Point for a curve, this is an equilibrium point
99 Ending Point for a curve, this is an equilibrium point
H Hopf Point
BP Branch Point
LP Limit Point

5.4 User Points


In order to detect and locate a user point, say, defined by the user function
userf1, the following lines and options need to be included.
UserInfo.name = ’userf1’;
UserInfo.state = 1;
UserInfo.label = ’u1’;
opt = contset(opt,’Cont UserFuncInfo’,UserInfo);
This allows CL MATCONTL to identify and label the user points.

References
[1] D. Bindel, J. Demmel, and M. Friedman, Continuation of invariant
subspaces for large bifurcation problems, in Proceedings of the SIAM Con-
ference on Linear Algebra, Williamsburg, VA, 2003.
[2] , Continuation of invariant subspaces for large bifurcation problems,
Tech. Report UCB/EECS-2006-13, EECS Department, University of Cali-
fornia, Berkeley, February 13 2006.
[3] , Continuation of invariant subspaces for large bifurcation problems,
SIAM J. Sci. Comput., 30 (2008), pp. 637–656.

25
[4] D. Bindel, W. Demmel, M. Friedman, W. Govaerts, and
Y. Kuznetsov, Bifurcation analysis of large equilibrium systems in mat-
lab, in Proceedings of the ICCS conference 2005, volume 3514/2005, At-
lanta, GA, 2005, pp. 50–57.
[5] J. W. Demmel, L. Dieci, and M. J. Friedman, Computing connecting
orbits via an improved algorithm for continuing invariant subspaces, SIAM
J. Sci. Comput., 22 (2001), pp. 81–94.
[6] A. Dhooge, W. Govaerts, and Yu.A. Kuznetsov, matcont: A mat-
lab package for numerical bifurcation analysis of odes., ACM TOMS., 29
(2003), pp. 141–164.
[7] A. Dhooge, W. Govaerts, Yu.A. Kuznetsov, W. Mestrom, and
A. M. Riet, MATLAB continuation software package CL MATCONT,
Jan. 2003. http://www.math.uu.nl/people/kuznet/cm/.
[8] L. Dieci and M. J. Friedman, Continuation of invariant subspaces, Nu-
merical Linear Algebra and Appl., 8 (2001), pp. 317–327.
[9] M. Friedman, W. Govaerts, Y. Kuznetsov, and B. Sautois, Con-
tinuation of homoclinic orbits in matlab, in Proceedings of the ICCS con-
ference 2005, volume 3514/2005, Atlanta, GA, 2005, pp. 263–270.
[10] M. Friedman and W. Qiu, On the location and continuation of hopf
bifurcations in large-scale problems, Int. J. Bif. and Chaos, 18 (2008),
pp. 1589–1597.

[11] M. J. Friedman, Improved detection of bifurcations in large nonlinear


systems via the Continuation of Invariant Subspaces algorithm, Int. J. Bif.
and Chaos, 11 (2001), pp. 2277–2285.
[12] W. Govaerts, Numerical methods for bifurcations of dynamical equilibria,
SIAM, Philadelphia, 2000.
[13] Yu. A. Kuznetsov, Elements of Applied Bifurcation Theory, Third edi-
tion, Springer-Verlag, New York, 2004.

26

S-ar putea să vă placă și