bertinilab: a matlab interface for solving systems …ajnewell/bertinilab_postprint.pdf · numer...

16
Numer Algor DOI 10.1007/s11075-015-0014-6 ORIGINAL PAPER BertiniLab: A MATLAB interface for solving systems of polynomial equations Daniel J. Bates 1 · Andrew J. Newell 2 · Matthew Niemerg 3,4 Received: 18 November 2014 / Accepted: 26 May 2015 © Springer Science+Business Media New York 2015 Abstract A MATLAB interface to the numerical homotopy continuation package Bertini is described. Bertini solves systems of polynomial equations. BertiniLab can be used to create input files for Bertini, run Bertini and process the solutions. All fea- tures of Bertini 1.5 are supported. The user can define the system of equations using a MATLAB numerical function, and vector and matrix operations are allowed. An object-oriented design allows the user to separate the statement of the problem from the details of the solution; the user can create subclasses to provide shortcuts or to tailor BertiniLab to a specific kind of problem. A complete example of an application to ferromagnetism is presented. Keywords Polynomial system · Numerical algebraic geometry · Bertini · MATLAB Partially supported by NSF grants DMS-1025544, DMS-1025564 and EAR-1417095. Andrew J. Newell andrew [email protected] Daniel J. Bates [email protected] Matthew Niemerg [email protected] 1 Department of Mathematics, Colorado State University, Fort Collins, CO, USA 2 Department of Marine, Earth and Atmospheric Sciences, Campus Box 8208, North Carolina State University, Raleigh, NC 27695-8208, USA 3 Simons Institute for the Theory of Computing, UC Berkeley, Berkeley, CA 94720-2190, USA 4 Present address: Institute for Interdisciplinary Information Sciences, Tsinghua University, Beijing, 100084, China

Upload: ngothien

Post on 30-Aug-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

Numer AlgorDOI 10.1007/s11075-015-0014-6

ORIGINAL PAPER

BertiniLab: A MATLAB interface for solving systemsof polynomial equations

Daniel J. Bates1 ·Andrew J. Newell2 ·Matthew Niemerg3,4

Received: 18 November 2014 / Accepted: 26 May 2015© Springer Science+Business Media New York 2015

Abstract A MATLAB interface to the numerical homotopy continuation packageBertini is described. Bertini solves systems of polynomial equations. BertiniLab canbe used to create input files for Bertini, run Bertini and process the solutions. All fea-tures of Bertini 1.5 are supported. The user can define the system of equations usinga MATLAB numerical function, and vector and matrix operations are allowed. Anobject-oriented design allows the user to separate the statement of the problem fromthe details of the solution; the user can create subclasses to provide shortcuts or totailor BertiniLab to a specific kind of problem. A complete example of an applicationto ferromagnetism is presented.

Keywords Polynomial system · Numerical algebraic geometry · Bertini · MATLAB

Partially supported by NSF grants DMS-1025544, DMS-1025564 and EAR-1417095.

� Andrew J. Newellandrew [email protected]

Daniel J. [email protected]

Matthew [email protected]

1 Department of Mathematics, Colorado State University, Fort Collins, CO, USA

2 Department of Marine, Earth and Atmospheric Sciences, Campus Box 8208, North CarolinaState University, Raleigh, NC 27695-8208, USA

3 Simons Institute for the Theory of Computing, UC Berkeley, Berkeley, CA 94720-2190, USA

4 Present address: Institute for Interdisciplinary Information Sciences, Tsinghua University,Beijing, 100084, China

Numer Algor

1 Introduction

Systems of polynomial equations, the subject of algebraic geometry, arise inmany applications. Examples include equations for equilibria in chemical reac-tions [10] and systems of magnets [12]; kinematic equations in robotics [16];optimal control of electronic devices [13]; and discretization of differential equa-tions [7]. Efficient solution techniques for such problems are a relatively recentdevelopment.

MATLAB, a widely used commercial product for solving mathematical prob-lems, provides several kinds of tools for solving polynomial systems, each withits own limitations. The builtin function roots finds the roots of polynomialsin one variable by finding the eigenvalues of the companion matrix. General-purpose solvers such as solve might find a single root of an equation, givenan initial guess that is not too far from the solution; but there is no sys-tematic way of finding all the roots. Finally, the Symbolic Toolbox providesan interface to MuPAD, a combination of symbolic engine and language; itcan be used to find closed-form solutions for some polynomial systems. How-ever, many polynomial systems of practical interest do not have such analyticalsolutions.

Numerical algebraic geometry is a collection of methods for systematically find-ing all the roots of systems of polynomial equations, even if there are infinitely manysolutions (curves, surfaces, etc.). These methods have homotopy continuation at theircore.

In homotopy continuation, one must deform the solutions of a starting poly-nomial system (typically chosen automatically by software) into the solutions ofthe system of interest. After an appropriate start system is chosen and solved, onecreates a parametrized polynomial system, i.e., a homotopy from the start sys-tem to the target system, and uses numerical continuation techniques to followsolution curves from the roots of the start system to those of the target system.Homotopy continuation is implemented in PHCpack [15], HOM4PS-2.0 [9] andBertini [3]. Each package requires a different set of algorithms. For example,PHCpack and HOM4PS-2.0 provide polyhedral homotopy methods while Bertinidoes not. Conversely, Bertini provides adaptive multiprecision while the othersdo not.

PHCpack has a MATLAB interface, PHClab [6]. It requires some effort to setup a polynomial system for solution by PHClab, as the system must be expressedin a “tableau” format in which the prefactors and exponents must be laid outin an array. Aside from the time and effort to transform the polynomial sys-tem into this format, this expansion into a monomial basis can cause unnecessaryinefficiency.

Bertini requires an input file in which variables, parameters, and constants aredeclared and the polynomial equations laid out in symbolic form, allowing for the useof subfunctions. In this article, we describe BertiniLab, a newMATLAB interface forBertini that creates a Bertini input file, runs Bertini and collects the output for use inMATLAB. This package extends the reach of polynomial system solving for users ofMATLAB.

Numer Algor

Algorithms such as regeneration [2, 8] in addition to software packages such asParamotopy [1] provide additional mechanisms to make homotopy continuation moreefficient in specific situations.

2 Bertini

This section provides a coarse description of the functionality and input/output ofBertini. See [5] for finer details.

Bertini solves systems of polynomial equations. A system of equations needs notbe square (having the same number of variables and equations) for Bertini to solveit. If the system is underdetermined, Bertini can find positive-dimensional solutions.If it is overdetermined, Bertini transforms it into a square system and solves thatsystem. This squaring process can introduce solutions of the squared system that arenot solutions of the original system [5]. Bertini automatically identifies and discardssuch extraneous solutions.

Bertini can find zero-dimensional solutions (isolated points) using a variety ofhomotopies, including total-degree homotopy, multihomogeneous homotopy, andregeneration. It can also use parameter homotopies to more efficiently solve systemsthat are the same aside from one or more parameters that are varied. In these algo-rithms, the user specifies the type of homotopy (or allows Bertini to use the default)and then lets Bertini handle details like constructing a start system. Alternatively,Bertini also allows a user-defined homotopy.

To avoid problems arising from ill-conditioning of polynomial systems, Bertiniuses adaptive precision and endgame algorithms to compute highly singular solu-tions. It also provides tools for endpoint sharpening if the user wants to increase theprecision of some of the roots. The value of the polynomial function or its Jacobiancan be returned for a given point.

Bertini can also find positive-dimensional solution sets using witness sets [5, 14],and these can be used to obtain irreducible decompositions of algebraic sets. The usercan request additional random samples of a positive-dimensional set or determinewhether a given point is a member of that set.

To call Bertini, an input file is needed. This file is organized in two blocks. Thefirst, the configuration block, specifies the type of homotopy, tolerances and otherdetails of the solution method. The other block is the input block, which declaresvariables, constants and parameters and defines the polynomial functions. These areall represented in symbolic form. A simple example of a Bertini input file follows:CONFIG

FinalTol: 1e-20;

END;

INPUT

function f;

variable_group x;

f = xˆ2 - 1;

END

Numer Algor

This tells Bertini to find the solutions for the single, univariate equation x2 = 1 to 20digits of accuracy.

For some applications, another file with a list of points is needed (for example, astart file for a user homotopy). A few types of run (component sampling, endpointsharpening and witness set printing) have a default interactive mode, although thiscan be automated by providing the user responses in a file.

Bertini writes a summary of a run to the screen with information on theconfiguration; the number of paths tracked; the number of real and non-real,singular and non-singular solutions; a count of solutions by multiplicity; and alist of output files. These always include main data, a human-readable col-lection of information on the roots. In addition, there are a few files withsimple formats that can be easily read by a computer. For zero-dimensionalruns, these include raw solutions, raw data, nonsingular solutionsand singular solutions. For positive-dimensional runs, the main files aremain data and witness data. Other output files may be produced dependingon the homotopy. BertiniLab is able to read these files and make the informationavailable within MATLAB.

3 Design of BertiniLab

BertiniLab uses the object-oriented capabilities of MATLAB. It was designedwith the following goals in mind. First, it should provide access to all the func-tionality of Bertini. For example, it should be able to run a user homotopyor parameter homotopy; use any of the Bertini methods for sharpening solu-tions; find positive-dimensional solutions; and support the interactive modes thatBertini provides for endpoint sharpening, component sampling and witness setprinting.

Second, BertiniLab should be easy to use. The effort involved in creating a Bertinirun should be, at worst, comparable to creating a Bertini input file. The syntax forusing it should be straightforward and easy to guess for someone who has usedBertini, while any overloaded MATLAB methods should behave in a way that aMATLAB user would expect.

Third, BertiniLab should be flexible. It should allow users to generate the equa-tions to be solved using a MATLAB function and allow the function to use matrix andvector operations. It should also allow users to specialize the behavior of BertiniLabby subclassing it. It should accept a variety of input types, including strings and num-bers, and should be able to convert the results into a variety of output types. It shouldalso accept symbolic objects in the MATLAB Symbolic Toolbox, but be independentfrom the toolbox.

4 Downloading and installing

BertiniLab requires an installation of Bertini [4]. There are compiled versions ofBertini for 32 and 64 bit Linux, 64 bit Mac OS X, and 32 bit Windows XP (the

Numer Algor

last requires Cygwin to be installed). The source code is also available. Down-loads and instructions for installing can be found at https://bertini.nd.edu/. BertiniLabis available from Netlib (http://www.netlib.org/numeralgo/) as the na42 package.It is distributed as a compressed archive file, which can be uncompressed to anylocation on the user’s computer and then added to the MATLAB path (a script forimplementing this is provided). Extensive documentation is provided; the user shouldbegin with the Getting Started document in the main folder.

BertiniLab was tested with Bertini 1.4 and MATLAB versions R2012b, on Win-dows, Mac, and Linux. A suite of unit tests are included; these use the MATLABUnit Testing Framework (see docsearch "Unit Testing Framework").The command runAllTests in the folder test will run all the tests. This testingframework only dates back to 2013; for earlier versions, a suite of tests is pro-vided that requires the MATLAB xUnit Test Framework by Steve Eddings. Thispackage can be downloaded from MATLAB Central (http://www.mathworks.com/matlabcentral/fileexchange/).

The BertiniLab distribution contains a suite of examples based on [4] in the folderexamples. All the code displayed in this manuscript can be found in the examples/codeUsedInManuscript.

5 Implementation

5.1 Class polysym

The key to making Bertini easy to use and flexible is a class called polysym. Thisclass takes care of conversion between various data types and the text of Bertini inputand output files. It also supports a variety of arithmetic and vector algebra commandsthat are commonly used in MATLAB. It resembles the MATLAB Symbolic Toolbox,but cannot do symbolic algebra. Instead, its purpose is essentially one of translation.It is also limited to operations that are consistent with forming polynomial expres-sions (along with operations like cos, sin and exp that Bertini accepts), so it cancatch a lot of errors before a Bertini input file is generated.

An example of a simple use of polysym follows:>> x = polysym(‘x’); y = polysym(‘y’);>> disp( xˆ2 + cos(y))

xˆ2+cos(y)

(The string >> represents a MATLAB prompt. The builtin command disp is a morecompact way of displaying output than the alternative that results when a semicolonis left off the end of a command line.) The constructor polysym can take strings, cellarrays of strings, and double precision inputs; if the Symbolic Toolbox is installed, itcan also accept vpa or sym objects.

For definitions like x=polysym(‘x’), where the symbol contains its own name,there is the shortcut polysyms. The following are equivalent:>> x = polysym(‘x’); y = polysym(‘y’);>> polysyms(‘x’,‘y’)>> polysyms x y

Numer Algor

Vectors and matrices can be defined in a manner similar to that of the SymbolicToolbox command sym.>> v = polysym(‘v’,[1 2]); disp(v)

v1 v2

>> M = polysym(‘M’,2); disp(M)

M1_1 M1_2

M2_1 M2_2

Matrix operations have the same syntax as for numeric calculations:>> disp(M*v.’)M1_1*v1+M1_2*v2

M2_1*v1+M2_2*v2

(The MATLAB symbol .’ represents the transpose.) If a vector is given for thesecond argument, it is interpreted as the number of rows and columns. A scalar isexpanded to represent the dimensions of a square matrix, so the definition of M in thesecond command is equivalent to M = polysym(‘M’,[2 2]).

Numbers can be entered in polysym directly or combined with a polysymobject (which takes precedence in an arithmetic operation):>> x = polysym(1+1i);

>> disp(x*(1-1i))

(1+1*I)*(1-1*I)

As in Bertini, the square root of −1 is represented by the capital letter I .One of the main reasons for creating polysym is that polysym variables can be

input to a MATLAB function to get a symbolic expression:>> f = @(y,z) zˆ3 + yˆ2*z + 1;

>> polysyms y z

>> disp(f(cos(y),z))

zˆ3+cos(y)ˆ2*z+1

A little care must be used in designing the function. MATLAB calculates expres-sions from left to right. Any numeric expression will be evaluated, resulting in apossible reduction of accuracy. For example,>> disp(9/16*x)

0.5625*x

>> disp(x*9/16)

x*9/16

Thus, to avoid loss of precision, polysym objects should be post-multiplied bynumbers.

It is common in MATLAB to use the builtin command zeros to pre-allocatevectors. However, a command sequence like>> y = polysym(‘y’,2);>> x = zeros(2);

>> x(1) = y(1)

Numer Algor

will result in an error because it is trying to assign a polysym object to a numericarray. If we know in advance that the variable y will have class polysym, then xcan be defined using>> x = polysym(0,size(y));

If x is used in a function that needs to also accept numeric input, it can beinitialized as follows:>> x = y*0;

5.2 Class BertiniLab

The class BertiniLab has a property (the MATLAB term for a data holder) foreach of the declarations in a Bertini input file. These include variable group andhom variable group, the declarations for most homotopies. User homotopiesrequire variable, path variable and parameter (the last also being usedin a different way for parameter homotopies). There are properties for declarationsof constants, subfunctions and defined subfunctions (the latter containing the nameof a file with declarations in it). The properties random and random real areavailable if the user wants Bertini to generate random numbers for some variables; butMATLAB can also be used for this purpose. The property function def containsthe function declarations, as described below.

As a simple example of constructing a BertiniLab object, suppose we wish tosolve the following system for two variables (Example 1.1 in [5]):

x2 − 1 = 0 (1)

y2 − 4 = 0. (2)

The solution set consists of the four points (±1, ±2). The BertiniLab object forthis problem can be constructed as follows:polys = BertiniLab(‘variable group’,{‘x’,‘y’}, ...

‘function def’,{‘xˆ2-1’,‘yˆ2-4’});The symbolic input is in the form of cell arrays of strings. Inside polys, theyare converted to polysym arrays. An alternative is to explicitly define polysymobjects for the variables, as we will do in the next example.

The command for solving the system ispolys = solve(polys);

or, equivalently,polys = polys.solve;

The first is a functional form and the second is a syntax used for class methodsin MATLAB. Note that the output is assigned to polys. This allows it to storetwo important results of the run. The first is the property order of variables,which keeps track of the order in which the variables were declared in theBertini input file. This is important for retrieving the solutions later and assign-ing them to the correct variables. The second is solve summary, which capturesthe output that normally goes to the screen. The summary for this run reports

Numer Algor

that four paths were tracked and there are four non-singular, finite solutionsof multiplicity one. Thus, these solutions can be found in all of the followingfiles: raw solutions, nonsingular solutions, finite solutionsand real finite solutions.

BertiniLab has two methods for retrieving the output from a Bertini file. Thefirst, read raw data, reads the file raw data, which contains both the solutionpoints and a set of diagnostics for each point. The other files can be read usingmatch solutions. This reads a set of solutions and matches it to the appropriatevariables.sols = polys.match solutions(‘real finite solutions’);This stores the solutions in a structure array with a field for each variable. Thesolutions are stored as polysym objects, which can be converted to double preci-sion numbers, cell arrays of strings, or (if the Symbolic Toolbox is installed) sym orvpa objects. The following code converts the solutions to double precision and stripsaway the negligible complex part before displaying the result:x = real(double(sols.x));

y = real(double(sols.y));

disp([x(:) y(:)])

1 2

1 -2

-1 2

-1 -2

We will now solve the system (from Appendix A in [5])

(29/16)z31 − 2z1z2 = 0 (3)

z2 − z21 = 0. (4)

We define the variables as polysym objects,polysyms z1 z2

and a MATLAB functionf = @(x,y) [(29/16)*xˆ3 - 2*x*y; y - xˆ2];

The BertiniLab object for this problem can now be constructed and solved:polys = BertiniLab(‘function def’,f(z1,z2), ...

‘variable group’,[z1 z2]);

polys = solve(polys);

When the function is given polysym arguments, the square brackets collect the out-put in a vector. This can be a row or column vector; in MATLAB syntax, a semicolonbetween vector elements makes it a column vector. In a Bertini input file, each poly-nomial equation is given a name. By default, BertiniLab generates a series ofnames (eqn1, eqn2, . . . ). The user can choose different names by assigning a valueto the property function name.

The summary of the run concludes withTruncated infinite paths: 3 - try adjusting SecurityMaxNorm

or set SecurityLevel to 1 in the input file

Please see ‘failed paths’ for more information

about these paths.

Numer Algor

We can take the advice of Bertini and solve the problem again with the security levelset to 1:polys.config = struct(‘SecurityLevel’,1);polys = solve(polys);

This time there are no truncated paths. The summary includes a number of tablesinforming us that there is a finite singular solution with multiplicity 3 and a solutionat infinity with multiplicity 3.

5.3 Controlling variable groups

To get the two triple solutions in the above example, Bertini explored 6 paths. Forthis problem, we can make a small improvement in the performance by putting z1and z2 in separate variable groups, so a multihomogeneous homotopy is used. Thisis done by putting them in curly brackets, {z1,z2}, instead of square brackets. Thissubtlety has to do with the way arrays are created in MATLAB (curly brackets areused to create cell arrays). Using a multihomogeneous homotopy, only 5 paths areneeded for this problem as the singular solution at infinity now has multiplicity 2.

In a problem with three variables z1,z2,z3, some examples of grouping include[z1 z2 z3] (all one group), {[z1 z2], z3} (two groups with z1 and z2 inone of them), and {z1, z2, z3} (three groups).

6 Customizing BertiniLab

To retrieve solutions from a call to Bertini, the user must explicitly read the solutionsfrom one of the output files. This is an example of the tradeoff between convenienceand generality in the design of BertiniLab. It would often be more convenient toautomatically read all the solutions from raw data into an output structure whenthe system is solved. However, this is not always desirable. For example, in manyscientific applications, only the real finite solutions are of interest, so it is oftenmore desirable to import data from real finite solutions. The user can tai-lor BertiniLab to their particular needs by creating a subclass, as we will show inSection 7.

As an example of customization, the following function takes one input,a system of equations, and returns a structure with the solutions in doubleprecision. The overloaded method symvar in polysym finds the variablesautomaticallyfunction sols = findRealRoots(polyFun)

polyFun = polysym(polyFun);

vars = symvar(polyFun);

% Solve and retrieve real finite solutions.

polys = BertiniLab(‘function def’,polyFun, ...

‘variable group’,vars);polys = solve(polys);

Numer Algor

sols = polys.match solutions(‘real finite solutions’);% Convert solutions to double precision and remove

% negligible imaginary part.

sols = structfun(@double,sols,‘UniformOutput’,false);sols = structfun(@real,sols,‘UniformOutput’,false);end

A call to this function would look like this:sols = findRealRoots({‘xˆ2-1’; ‘yˆ2-4’});While having the advantage of simplicity, this function is not flexible and does notwarn the user of any problems with the solution. A more complete function couldmonitor BertiniLab properties that flag errors and use the last part of the solutionsummary as a warning:if polys.has_failed_paths || polys.has_path_crossings

results = polys.solve_summary;

istart = strfind(results,‘Paths Tracked’);warning(results(istart:end));

end

If the function is modified to return a BertiniLab object, the configuration can thenbe changed as needed.

7 Subclassing and parameter homotopy

Many systems of polynomials have fewer solutions than are predicted by a multi-homogeneous Bezout count. For problems that involve finding solutions for manysystems that are the same except for the values of some parameters, a parameterhomotopy often provides a better estimate of the true number of roots. It begins withan ab initio run using random complex values for the parameters. This determinesthe number of roots for a generic version of the system, and those roots can be start-ing points for solving the system for other values of the parameters. In this sectionwe will describe a problem for which the number of paths to follow is reduced byparameter homotopy and further reduced by taking the symmetry of the system intoaccount.

The possible magnetization states of microscopic ferromagnets can be determinedif the dependence of energy on magnetization is known. Here we consider a simpleexample, a single-domain magnet with a mixture of uniaxial and cubic anisotropy[11]. The magnetization has fixed magnitude, so it can be represented by a unit vectorm = (m1, m2, m3). The energy of the magnet is

E = K(1 − m2

3

)+ m2

1m22 + m2

2m23 + m2

3m21, (5)

where K is a parameter, the ratio of two magnetocrystalline anisotropy constants. Toensure that the magnetization remains a unit vector, we add a Lagrange multiplier:

E′ = E + λ(m2

1 + m22 + m2

3 − 1)

. (6)

Numer Algor

If the magnet is in an equilibrium state, the derivatives of E with respect tom1, m2, m3 and λ are all zero. It can be shown analytically that there are five sets ofsolutions [11]:

(0, 0, ±1)

(±1, 0, 0) , (0, ±1, 0)(±1/

√2, ±1/

√2, 0

)

(±a, 0, ±b) , (0, ±a, ±b)

(±c, ±c, ±d) ,

where the variables a, b, c, d depend on K . Within each set, the solutions have thesame energy and are mapped onto each other by symmetry operations.

To solve this system, we can create a subclass of BertiniLab that accepts aset of equations and an optional set of constraints. It also uses multihomogeneoushomotopy, separating the Lagrange multipliers from the physical variables.classdef solveWithConstraints < BertiniLab

methods

function polySystem =

solveWithConstraints(gradFcn,N,constrFcn,varargin)

% Create a symbolic state vector.

% Its components will be the

% values to solve for.

stateVector = polysym(‘x’,[N 1]);

varGroup = stateVector;

% Construct gradient vector

g = gradFcn(stateVector);

if nargin > 2 && ˜isempty(constrFcn)

[c,gradc] = constrFcn(stateVector);

lambda = polysym(‘lambda’,size(c));varGroup = {varGroup,lambda};

lambda = ...repmat(lambda,1,numel(g)/numel(lambda)).’;

g = [g + lambda.*gradc; c];

end

% Define the polynomial system

polySystem = ...polySystem@BertiniLab(‘variable group’,varGroup, ...

‘function def’,g,varargin{:});

Numer Algor

end

end

end

In the constructor, the last argument (varargin) is used to pass on any additionalarguments to BertiniLab.

This subclass requires constrFcn to have two outputs:[c,gradc] = constrFcn(x),

where c is the constraint function and gradc is its gradient with respect to m. Wecan construct the input functions as MATLAB anonymous functions:anisotropyFcn = @(x,K) 2*[x(1)*(x(2)ˆ2+x(3)ˆ2); ...

x(2)*(x(1)ˆ2+x(3)ˆ2); ...

x(3)*(x(1)ˆ2+x(2)ˆ2) - K*x(3)];

constrFcn = @(x) deal(sum(x.ˆ2)-1,2*x(:));

We solve this system for a trial value of K:Kval = 0.2; N = 3;

% make a function of x only

gradFcn = @(x) anisotropyFcn(x,Kval);

polys = ...

solveWithConstraints(gradFcn,N,constrFcn,‘config’, ...

struct(‘SecurityLevel’,1));polys = solve(polys);

(The setting for SecurityLevel is needed to avoid truncated infinite paths.) Theresult, after tracking 54 paths, is 26 real, finite solutions and a solution at infinitywith multiplicity 28.

Now we do the ab initio solve for parameter homotopy:polysyms K

gradFcn = @(x) anisotropyFcn(x,K);

polys = solveWithConstraints(gradFcn,N,constrFcn,‘config’, ...

struct(‘ParameterHomotopy’,1,‘SecurityLevel’,1), ...

‘parameter’,K);Again, there are 54 paths and 26 solutions. If a parameter homotopy run is now donefor another value of K , it will follow 26 paths. However, the system of equations isinvariant under a change of sign of any of the components ofm as well as an exchangeof the x and y components. This symmetry can be used to reduce the number ofsolutions to five:vars = polys.read solutions(‘nonsingular solutions’);v = round(double(vars)*1e10);

v = [sort(v(1:2,:)); v(3:4,:)];

[˜,ia] = unique(abs(v.’),‘rows’);vars_reduced = vars(:,ia(:));

An example of a run using parameter homotopy follows:polys.starting_points = vars_reduced;

polys.config.ParameterHomotopy = 2;

polys.final_parameters = 0.2;

polys = solve(polys,‘paramotopy.input’);

Numer Algor

Now 5 solutions are obtained after following 5 paths, a substantial reduction from 54.The result of solving the system for two hundred values of K between −1 and 1

is shown in Fig. 1.There are ten fixed solutions at (±1, 0, 0), (0, ±1, 0), (0, 0, ±1), and

(±1/√2, ±1/

√2, 0), and some solutions that migrate from the z axis to the equator

as K goes from −1 to 1.

8 Positive-dimensional solutions

In real space the solutions form 16 distinct curves. How many distinct curves arethere in complex space? Bertini has extensive tools for computing complex positive-dimensional solutions of a polynomial system. In particular, it can be used to computethe numerical irreducible decomposition of the solution set. Simply put, this is acatalog of all complex irreducible components, i.e., the set of all connected compo-nents after removing all singular solutions, along with some auxiliary data [5]. TheBertiniLab method irreducible decomposition invokes this solution:

m = sym(‘m’,[3 1]);

syms K lambda

E = K*(1-m(3)ˆ2)+ m(1)ˆ2*m(2)ˆ2+m(2)ˆ2*m(3)ˆ2+m(3)ˆ2*m(1)ˆ2 ...

+ lambda*(m(1)ˆ2+m(2)ˆ2+m(3)ˆ2-1);

f = [diff(E,m(1)); diff(E,m(2)); diff(E,m(3)); diff(E,lambda)];

polys = BertiniLab(‘variable group’,[m; lambda; K], ...

‘function def’,f);polys = irreducible_decomposition(polys);

Part of the solution summary looks like this:************** Decomposition by Degree **************

Dimension 1: 14 classified components

-----------------------------------------------------

degree 1: 10 components

degree 4: 4 components

*****************************************************

The 10 fixed points (degree 0 solutions for fixed K) are dimension 1, degree 1 solu-tions (lines) whenK is allowed to vary. The 16 real curves are contained in 4 complexcurves.

For each irreducible component, Bertini returns a set of witness points. Theseare generic points from the component, found by intersecting the componentwith a randomly chosen linear space of complementary dimension. The methodirreducible decomposition automatically returns this information in twoproperties, witness points (which just contains the witness points) andcomponents (which has information on each component, including the dimensionand degree). The organization of witness points is similar to that of isolated

Numer Algor

Fig. 1 Solutions for themagnetization of the systemwith cubic and uniaxialanisotropy. The color code is thevalue of the parameter K

−1

−0.5

0

0.5

1

point solutions, a structure array with a field for each variable and each variableparameter.

For our example, we find the degree 4 curves and examine the witness points todetermine how they correspond to the analytical solutions. The commandidx = find([polys.components.degree]==4);

returns the indices of the components, anddisp(double(polys.witness_points(idx(1)).m))

examines one set of witness points with five digits of precision. The number of wit-ness points on each component is the degree of the component. One may worry thatthis number could depend on the choice of random slice. However, classical theoremsfrom algebraic geometry guarantee that the number of points in this intersection willalways be the same so long as the random linear slice is chosen away from a measurezero set of the parameter space of all possible linear slices. Methods of this sort arereferred to as probability one algorithms.

An example from one run of Bertini, with a row for each witness point, follows:0.6772 - 0.1068i 0.6772 - 0.1068i 0.4547 + 0.3181i

-0.7591 + 0.1877i -0.7591 + 0.1877i -0.4969 - 0.5734i

0.7732 - 0.1025i 0.7732 - 0.1025i -0.3059 - 0.5180i

-0.6357 + 0.1764i -0.6357 + 0.1764i 0.6204 + 0.3616i

With these tools, it is easily confirmed that the four components have the generalform (a, 0, b), (0, a, b), (c, c, d), and (c, −c, d). With the constraint |m| = 1, theintersection of each component with real space is a circle. Note that the points foundwill be different for each run as Bertini chooses a different random linear slice foreach run.

BertiniLab also has a method for testing membership of a point. For example, thefollowing returns a logical array with one of the degree-1 components marked true.ismember = polys.membership(struct(‘m’,[0; 0; 1],‘lambda’,1, ...

‘K’,1));A given component can also be sampled. A dimension and component number can

be specified in a structure; in Bertini, the component numbers increase from zero,so in BertiniLab the nth element of an array of components has component numbern − 1. However, one can also simply choose one of the elements and pass it to themethod sample. The following returns five points from the 13th component:

Numer Algor

npoints = 5;

comp_num = 13;

sample_points = polys.sample(polys.components(com_num), ...

npoints);

9 Discussion

Although Bertini is a useful tool for solving polynomial systems, there is a definitelearning curve for using the software and understanding the methods and data typesof the field of numerical algebraic geometry. BertiniLab simplifies this learning curvewhile also simplifying the use of Bertini in MATLAB. Those wishing to use BertinifromMATLAB no longer need to write Bertini input files or parse rather complicatedBertini output files; BertiniLab automates these actions.

Furthermore, because BertiniLab can take advantage of vector and matrix oper-ations, it is more flexible than the Bertini input file. When vectors and matricesare used, it is not necessary to know the number of variables in advance. The sizeof the problem can be easily changed and the names of the variables automaticallygenerated.

For further examples of the uses of BertiniLab, including sharpening endpoints,regeneration, and user-defined homotopies, refer to the examples included with theBertiniLab distribution pulled from the book [5].

Acknowledgements This work was partially supported by NSF grant DMS-1025544 and NSF grantDMS-1025564.

References

1. Bates, D.J., Brake, D.A., Niemerg, M.E.: Paramotopy: Parameter homotopies in parallel (2015)2. Bates, D.J., Davis, B., Eklund, D., Hanson, E., Peterson, C.: Perturbed homotopies for finding all

isolated solutions of polynomial systems. Appl. Math. Comput. 247, 301–311 (2014)3. Bates, D.J., Hauenstein, J.D., Sommese, A.J., Wampler, C.W.: Bertini: Software for numerical

algebraic geometry. Available at http://www.nd.edu/∼sommese/bertini (2010)4. Bates, D.J., Hauenstein, J.D., Sommese, A.J., Wampler, C.W.: Bertini: Software for numerical

algebraic geometry. Web page. http://www.bertini.nd.edu/ (2010)5. Bates, D.J., Hauenstein, J.D., Sommese, A.J., Wampler, C.W.: Numerically Solving Polynomial

Systems with Bertin. SIAM (2013)6. Guan, Y., Verschelde, J.: PHClab: A MATLAB/Octave interface to PHCpack. In: Software for Alge-

braic Geometry, The IMA Volumes in Mathematics and its Applications, vol. 148, pp. 15–32. Springer,New York (2008). doi:10.1007/978-0-387-78133-4 2

7. Hao, W., Hauenstein, J.D., Hu, B., McCoy, T., Sommese, A.J.: Computing steady-state solutions fora free boundary problem modeling tumor growth by stokes equation. J. Comput. Appl. Math. 237(1),326–334 (2013)

8. Hauenstein, J., Sommese, A., Wampler, C.: Regeneration homotopies for solving systems of polyno-mials. Math. Comput. 80(273), 345–377 (2011)

9. Lee, T., Li, T., Tsai, C.: Hom4ps–2.0: Homotopy method for solving polynomial systems. Web page.http://www.math.nsysu.edu.tw/leetsung/works/HOM4PS soft.htm (2008)

10. Nam, K.M., Gyori, B.M., Brake, D., Bates, D.J., Gunawardena, J.: The parameter geography ofmultistability in protein post-translational modification (2014)

Numer Algor

11. Newell, A.J.: Superparamagnetic relaxation times for mixed anisotropy and high energy barriers withintermediate to high damping: I. Uniaxial axis in a < 001 > direction. Geochem. Geophys. Geosyst.7(3), Q03,016 (2006). doi:10.1029/2005GC001146

12. Newell, A.J.: Transition to superparamagnetism in chains of magnetosome crystals. Geochem.Geophys. Geosyst. 10(Q11Z08) (2009). doi:10.1029/2009GC002538

13. Rostalski, P., Fotiou, I.A., Bates, D.J., Beccuti, A.G., Morari, M.: Numerical algebraic geometry foroptimal control applications. SIAM J. Optim. 21(2), 417–437 (2011)

14. Sommese, A.J., Wampler II, C.W.: The Numerical Solution of Systems of Polynomials Arising inEngineering and Science. World Scientific, 401 (2005)

15. Verschelde, J.: Algorithm 795: PHCpack: a general–purpose solver for polynomial systems by homo-topy continuation. ACM Trans. Math. Softw. 25(2), 251–276 (1999). doi:10.1145/317275.317286

16. Wampler, C.W., Sommese, A.J.: Numerical algebraic geometry and algebraic kinematics. ActaNumerica 20, 469–567 (2011)