PDF documentation | Download O2scl |
gsl_vector
and gsl_matrix
, yet offer indexing with operator
[] and other object-oriented featuresThis is a beta version. The library should install and test successfully, and most of the classes are ready for production use. Some of the interfaces may change slightly in future versions. There are a few classes which are more experimental, and this is clearly stated at the top of the documentation for these classes.
INSTALL
has some details on this procedure. Generally, you should be able to run ./configure
and then type make
and make
install
. More information on the configure
command can also be obtained from ./configure --help
. O2scl requires the GSL libraries. If the configure
script cannot find them, you may have to specify their location in the CPPFLAGS
and LDFLAGS
environment variables (./configure --help
shows some information on this). The documentation is included in the distribution and automatically installed by make
install
.
After make
install
, you may test the library with make
o2scl-test
. At the end, the phrase All O2scl tests passed
indicates that the testing was successful.
This library requires GSL and is designed to work with GSL versions 1.12 or greater. Some classes may work with older versions of GSL, but this cannot be guaranteed. A CBLAS library is also required, and ./configure
will look for libcblas
first, and if not found then it will look for libgslcblas
. If neither is present, then you may have to manually specify a CBLAS library using the LIBS
and LDFLAGS
environment variables.
Range-checking for vectors and matrices is performed similar to the GSL approach, and is turned on by default. You can disable range-checking by defining -DO2SCL_NO_RANGE_CHECK
CPPFLAGS="-DO2SCL_NO_RANGE_CHECK" ./configure
The separate libraries O2scl_eos and O2scl_part are installed by default. To disable the installation of these libraries and their associated documentation, run ./configure
with the flags --disable-eoslib
or --disable-partlib
. Note that O2scl_eos depends on O2scl_part so using --disable-partlib
without --disable-eoslib
will not work.
There are several warning flags that are useful when configuring and compiling with O2scl . See the GSL documentation for an excellent discussion, and also see the generic installation documentation in the file INSTALL
in the O2scl top-level directory. For running configure
, for example, if you do not have privileges to write to /usr/local
,
CPPFLAGS="-O3" -I/home/asteiner/install/include" \ LDFLAGS="-L/home/asteiner/install/lib" ./configure -C \ --prefix=/home/asteiner/install
-I/home/asteiner/install/include
and -L/home/asteiner/install/lib
above ensures that the GSL libraries can be found (this is where they are installed on my machine). The --prefix=/home/asteiner/install
argument to ./configure
ensures that O2scl is installed there as well.The documentation is generated with Doxygen . In principle, the documentation can be regenerated by the end-user, but this is not supported and requires several external applications not included in the distribution.
Un-installation: While there is no explicit "uninstall" procedure, there are only a couple places to check. Installation creates directories named o2scl
in the include, doc and shared files directory (which default to /usr/local/include
, /usr/local/doc
, and /usr/local/share
) which can be removed. Finally, all of the libraries are named with the prefix libo2scl
and are created by default in /usr/local/lib. As configured with the settings above, the files are in /home/asteiner/install/include/o2scl
, /home/asteiner/install/lib
, /home/asteiner/install/share/o2scl
, and /home/asteiner/install/doc/o2scl
.
o2scl
(this namespace has been removed from the documentation for clarity). Numerical constants (many of them based on the GSL constants) are placed in separate namespaces (gsl_cgs, gsl_cgsm, gsl_mks, gsl_mksa, gsl_num, o2scl_const, and o2scl_fm). There are also two namespaces which hold integration coefficients, o2scl_inte_qag_coeffs and o2scl_inte_qng_coeffs. There are also some namespaces for the linear algebra functions, see Linear algebra for more information.parameter
, except when used in mathematical formulas as in gsl_
and classes derived from CERNLIB are preceeded by the prefix cern_
. Some of those classes derived from GSL and CERNLIB operate slightly differently from the original versions. The differences are detailed in the corresponding class documentation.Errors can be set by the user through the macros O2SCL_ERR, which sets an error, and O2SCL_ERR_RET, which sets an error and returns the error number.
The error handler, err_hnd is a global pointer to an object of type err_hnd_type. There is a global default error handler, def_err_hnd, of type err_hnd_cpp, which throws C++ exceptions, and an alternate default error handler, alt_err_hnd, of type err_hnd_gsl, which outputs an error message and aborts execution.
Generally, functions also follow the GSL-like behavior of calling a GSL-like error handler and (when appropriate) return a non-zero value. When functions succeed they return 0 (gsl_success). O2scl functions never reset the error handler. Also, object destructors do not generally call the error handler. Internally, O2scl does not use try
blocks, but these can easily be effectively employed by an O2scl user.
The list of GSL error codes (including a few extra ones for O2scl ) is given in the documentation for the file err_hnd.h. The default error handler can be replaced by simply assigning the address of a descendant of err_hnd_type to err_hnd.
Functionality similar to assert() is provided with the macro O2SCL_ASSERT, which exits if its argument is non-zero, and O2SCL_BOOL_ASSERT which exits if its argument is false.
One can instruct the library to use the GSL-like O2scl error handler alt_err_hnd by default, by defining the constant O2SCL_USE_GSL_HANDLER
. This is also useful if one wants to compile without C++ exceptions (which does have a small overhead).
Sometimes, it is undesirable to abort execution upon a failure to reach numerical convergence. While these failures are treated as errors (and by default an exception is thrown), some of the classes which attempt to reach numerical convergence have an option (e.g. mroot::err_nonconv) to turn this default behavior off for these convergence errors. To set these "convergence" errors in code provided by the user, the macros O2SCL_CONV and O2SCL_CONV_RET can be used.
Another related issue is that O2scl often calls functions which are supplied by the user, these user-designed functions may create errors, and the library needs to decide how to deal with them, even though it knows little about what is actually happening inside these user-defined functions. Most of the time, O2scl assumes that if a function returns a nonzero value, then an error has occured and the present calculation should abort.
gsl_success=0, (no error thrown)
gsl_failure=-1, exc_exception
gsl_continue=-2, (no error thrown)
gsl_edom=1, exc_range_error
gsl_erange=2, exc_range_error
gsl_efault=3, exc_runtime_error
gsl_einval=4, exc_invalid_argument
gsl_efailed=5, exc_exception
gsl_efactor=6, exc_runtime_error
gsl_esanity=7, exc_exception
gsl_enomem=8, exc_runtime_error
gsl_ebadfunc=9, exc_runtime_error
gsl_erunaway=10, exc_runtime_error
gsl_emaxiter=11, exc_runtime_error
gsl_ezerodiv=12, exc_overflow_error
gsl_ebadtol=13, exc_invalid_argument
gsl_etol=14, exc_runtime_error
gsl_eundrflw=15, exc_range_error
gsl_eovrflw=16, exc_overflow_error
gsl_eloss=17, exc_runtime_error
gsl_eround=18, exc_runtime_error
gsl_ebadlen=19, exc_invalid_argument
gsl_enotsqr=20, exc_invalid_argument
gsl_esing=21, exc_runtime_error
gsl_ediverge=22, exc_runtime_error
gsl_eunsup=23, exc_exception
gsl_eunimpl=24, exc_exception
gsl_ecache=25, exc_runtime_error
gsl_etable=26, exc_runtime_error
gsl_enoprog=27, exc_runtime_error
gsl_enoprogj=28, exc_runtime_error
gsl_etolf=29, exc_runtime_error
gsl_etolx=30, exc_runtime_error
gsl_etolg=31, exc_runtime_error
gsl_eof=32, exc_ios_failure
gsl_enotfound=33, exc_runtime_error
gsl_ememtype=34, exc_logic_error
gsl_efilenotfound=35, exc_ios_failure
gsl_eindex=36, exc_invalid_argument
gsl_outsidecons=37, exc_runtime_error
A simple example of this is provided by the multi-dimensional integrator composite_inte. It works by combining several one-dimensional integrators to integrate over a multi-dimensional hybercube. If the specified one-dimensional integrator goes out of scope an integration is attempted, the integration will fail, for example,
// How not to provide subobjects to O2scl classes void set_integrator(multi_inte<int> &mi) { gsl_inte_qag<size_t> one_dim_it[2]; mi.set_oned_inte(one_dim_it[0],0); mi.set_oned_inte(one_dim_it[1],1); } void function() { composite_inte<int> cit; set_integrator(cit); cit.minteg_err(func,2,a,b,pa,res,err); }
This will fail because the one-dimensional integration objects go out of scope (it's a local variable in the function and its destructor is called before the set_integrator()
function exits) before the minteg_err()
function is called.
examples
directory. After installation, they can be compiled and executed by running make
o2scl-examples
in that directory. This will also test the output of the examples to make sure it is correct. If all the examples succeed, the message All O2scl tests passed.
will appear at the end. The output for each example is placed in the corresponding file with a .scr
extension.
Alternatively, you can make the executable for each example in the examples
directory individually using, e.g. make ex_mroot
.
See Example source code for the documented source code of the individual examples
Also, the testing code for each class is occasionally useful for providing examples of their usage. The testing source code for each source file is named with an _ts.cpp
prefix in the same directory as the class source.
gsl_
prefix) and O2scl was specifically designed to be used with GSL. GSL is a must-have for most serious numerical work in C or C++ and is required for installation of O2scl .
cern_
prefix). CERNLIB is located at http://cernlib.web.cern.ch/cernlib/mathlib.html
gsl_inte_
). It is available at http://www.netlib.org/quadpack .
gsl_complex
are defined in cx_arith.h, but no constructor has been written. The object gsl_complex
is still a struct
, not a class
. For example, #include <o2scl/cx_arith.h> gsl_complex a={{1,2}}, b={{3,4}}; gsl_complex c=a+b; cout << GSL_REAL(c) << " " << GSL_IMAG(C) << endl;
In case the user needs to convert between gsl_complex
and std::complex<double>
, two conversion functions gsl_to_complex() and complex_to_gsl() are also provided in cx_arith.h.
A short example using complex number arithmetic is given in Mandelbrot example .
double
[]. If there are two dimensions in the array, it is a "two-dimensional array", i.e. double
[][] . The word "vector" is reserved generic objects with array-like semantics, i.e. any type of object or class which can be treated similar to an array in that it has an function operator
[] which gives array-like indexing. Thus arrays are vectors, but not all vectors are arrays. There are a couple specific vector types defined in O2scl like ovector and uvector . The STL vector std::vector<double>
is also a vector type in this language. The word "matrix" is reserved for the a generic object which has matrix-like semantics and can be accessed using either operator()
or two successive applications of operator
[] (or sometimes both). The O2scl objects omatrix and umatrix are matrix objects, as is a C-style two-dimensional array, double
[][] . The header files are named in this spirit also: functions and classes which operate on generic vector types are in vector.h and functions and classes which work only with C-style arrays are in array.h . The word "tensor" is used for a generic object which has rank n
and then has n
associated indices. A vector is just a tensor of rank 1 and a matrix is just a tensor of rank 2.Most of the classes in O2scl which use vectors and/or matrices are designed so that they can be used with any appropriately-defined vector or matrix types. This is a major part of the design goals for O2scl and most of the classes are compatible with matrix and vector objects from GSL, TNT, MV++, uBlas, and Blitz++.
The first index of a matrix type is defined always to be the index associated with "rows" and the second is associated with "columns". The O2scl matrix output functions respect this notation as well, so that all of the elements of the first row is sent to the screen, then all of the elements in the second row, and so on. With this in mind, one can make the distinction between "row-major" and "column-major" matrix storage. C-style two-dimensional arrays are "row-major" in that the elements of the first row occupy the first locations in memory as opposed "column-major" where the first column occupies the first locations in memory. It is important to note that the majority of the classes in O2scl do not care about the details of the underlying memory structure, so long as two successive applications of operator[]
(or in some cases operator(,)
) works properly. The storage format used by omatrix and umatrix is row-major, and there are no column-major matrix classes in O2scl (yet).
operator
[] is very compatible with almost any vector type, matrix indexing is a bit more difficult. There are two options: assume matrix objects provide an operator
[] method which can be applied twice, i.e. m[i][j]
, or assume that matrix elements should be referred to with m(i,j)
. Most of the O2scl classes use the former approach so that they are also compatible with two-dimensional arrays. However, there are sometimes good reasons to want to use operator()
for matrix-intensive operations from linear algebra. For this reason, some of the functions given in the linalg
directory are specified in two forms: the first default form which assumes [][]
, and the second form with the same name, but in a namespace which has a suffix _paren
and assumes matrix types use (,)
.A
[ix][iy] where ix
and iy
are the A
[ix][iy] will be printed out with x on the "vertical axis" and y on the "horizontal axis", so it is sometimes useful to store data in the form A
[iy][ix] (for example, in the two dimensional interpolation class, twod_intp). In any case, all classes which take matrix data as input will document how the matrix ought to be arranged.
Vectors and matrices are designed using the templates ovector_tlate and omatrix_tlate, which are compatible with gsl_vector
and gsl_matrix
. Vectors and matrices with unit stride are provided in uvector_tlate and umatrix_tlate. The most commonly used double-precision versions of these template classes are ovector, omatrix, uvector and umatrix, and their associated "views" (analogous to GSL vector and matrix views) which are named with a _view
suffix. The classes ovector_tlate and omatrix_tlate offer the syntactic simplicity of array-like indexing, which is easy to apply to vectors and matrices created with GSL.
The following sections primarily discuss the operation objects of type ovector. The generalizations to objects of type uvector, omatrix, and the complex vector and matrix objects ovector_cx, omatrix_cx, uvector_cx, and umatrix_cx are straightforward.
"_cx"
, e.g. ovector_cx. See ovector_tlate.h, ovector_cx_tlate.h, omatrix_tlate.h, and omatrix_cx_tlate.h.free()
if necessary. In contrast to gsl_vector_alloc()
, ovector::allocate() will call ovector::free(), if necessary, to free previously allocated space. Allocating memory does not clear the recently allocated memory to zero. You can use ovector::set_all() with a zero argument to clear a vector (and similarly for a matrix).If the memory allocation fails, either in the constructor or in allocate(), then the error handler will be called, partially allocated memory will be freed, and the size will be reset to zero.
Although memory allocation in O2scl vectors is very similar to that in GSL, the user must not mix allocation and deallocation between GSL and O2scl .
gsl_vector_get()
and gsl_vector_set()
, or they can be modified through ovector::operator[] (or ovector::operator() ), e.g.
ovector a(4); a.set(0,2.0); a.set(1,3.0); a[2]=4.0; a[3]=2.0*a[1];
If you want to set all of the values in an ovector or an omatrix at the same time, then use ovector::set_all() or omatrix::set_all().
O2SCL_NO_RANGE_CHECK
is defined. It can be defined in the arguments to
./configure upon installation to turn off range checking. Note that this is completely separate from the GSL range checking mechanism, so range checking may be on in O2scl even if it has been turned off in GSL. Range checking is used primarily in the vector, matrix, and tensor get()
and set()
methods.To see if range checking was turned on during installation (without calling the error handler), use lib_settings_class::range_check().
Note that range checking in O2scl code is most often present in header files, rather than in source code. This means that range checking can be turned on or off in user-defined functions separately from whether or not it was used in the library classes and functions.
=
operator is performed according to what kind of object is on the left-hand side (LHS) of the equals sign. If the LHS is a view, then a shallow copy is performed, and if the LHS is a ovector, then a deep copy is performed. If an attempt is made to perform a deep copy onto a vector that has already been allocated, then that previously allocated memory is automatically freed. The user must be careful to ensure that information is not lost this way, even though no memory leak will occur.
For generic deep vector and matrix copying, you can use the template functions vector_copy(), matrix_copy(). These would allow you, for example, to copy an ovector to a std::vector<double>
object. These functions do not do any memory allocation so that must be handled beforehand by the user.
Vector_view unary operators:
Matrix_view unary operators:
Binary operators like addition, subtraction, and matrix multiplication are also defined for ovector, uvector, and related objects. The generic template for a binary operator, e.g.
template<class vec_t> vec_t &operator+(vec_t &v1, vec_t &v2);
O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,std::vector<double>, std::vector<double>)
The GSL BLAS routines can also be used directly with ovector and omatrix objects.
Note that some of these arithmetic operations succeed even with non-matching vector and matrix sizes. For example, adding a 3x3 matrix to a 4x4 matrix will result in a 3x3 matrix and the 7 outer elements of the 4x4 matrix are ignored.
gsl_vector
. ovector a(2); a[0]=1.0; a[1]=2.0; gsl_vector *g=(gsl_vector *)(&a); cout << gsl_vector_get(g,0) << " " << gsl_vector_get(g,1) << endl;
gsl_vector *g=gsl_vector_alloc(2); gsl_vector_set(0,1.0); gsl_vector_set(1,2.0); ovector &a=(ovector &)(*g); cout << a[0] << " " << a[1] << endl;
ovector a(2); gsl_vector *g=a.get_gsl_vector();
ovector a(2); a[0]=2.0; a[1]=1.0; gsl_vector_sort((gsl_vector *)(&a)); cout << a[0] << " " << a[1] << endl;
std::vector<double>
, you can use ovector_array std::vector<double> d; d.push_back(1.0); d.push_back(3.0); ovector_array aa(d.size,&(d[0])); cout << aa[0] << " " << aa[1] << endl;
However, you should note that if the memory for the std::vector
is reallocated (for example because of a call to push_back()
), then a previously created ovector_view will be incorrect.
std::vector<>
. This will work in O2scl classes, but may not be compatible with all of the GSL functions. This will break if the address of a ovector_tlate is given to a GSL function which accesses the block->size
parameter instead of the size
parameter of a gsl_vector
. Please contact the author of O2scl if you find a GSL function with this behavior.double x[2]={1.0,2.0}; gsl_vector_view_array v(2,x); gsl_vector *g=&(v.vector); gsl_vector_set(g,0,3.0); cout << gsl_vector_get(g,0) << " " << gsl_vector_get(g,1) << endl;
double x[2]={1.0,2.0}; ovector_array a(2,x); a[0]=3.0; cout << a << endl;
void function(const ovector_base &a);
const
void function(ovector_base &a);
If you intend for a function (rather than the user) to handle the memory allocation, then some care is necessary. The following code
is confusing because the user may have already allocated memory fora
. To avoid this, you may want to ensure that the user sends an empty vector. For example, class my_class { int afunction(ovector &a) { if (a.get_size()>0 && a.is_owner()==true) { O2SCL_ERR("Unallocated vector not sent to afunction().",1); return 1; } else { a.allocate(1); // do something with a return 0; } } };
get()
function, class my_class { protected: ovector a; public: int afunction() { a.allocate(1); // do something with a return 0; } int get_result(const ovector_view &av) { av=a; return 0; } };
template<class vec_t> class my_class { protected: vec_t a; public: int afunction(vec_t &a) { // do something with a return 0; } };
ovector_tlate::operator=(const data_t &val)
and ovector_tlate::ovector_tlate(size_t val) For example, after implementing operator=()
and executing the following ovector_int o1=2; ovector_int o2; o2=2;
o1
will be a vector of size two, and o2
will be an empty vector!To set all of the vector elements to the same value, use ovector_tlate::set_all(). Because of the existence of constructors like ovector_tlate::ovector_tlate(size_t val), the following code
ovector_int o1=2;
ovector_int o1(2);
ovector_int o1; o1=2;
ovector_int
o1(2)
; is preferable to ovector_int
o1=2
; to avoid confusion.
00 01 02 03 XX XX XX 10 11 12 13 XX XX XX
where XX
indicates portions of memory that are unreferenced. The tda can be accessed through, for example, the method omatrix_view_tlate::tda(). The get(size_t,size_t)
methods always take the row index as the first argument and the column index as the second argument. The matrices from umatrix_tlate have a trailing dimension which is always equal to the number of columns.
operator
[] and related methods are redefined to perform the reversal. If you want to make many calls to these indexing methods for a reversed vector, then simply copying the vector to a reversed version may be faster.ovector_const_view v1; const ovector_view v2; const ovector_const_view v3;
ovector_const_view
is a view of a const vector, the view may change, but the vector may not.const ovector_const_view
is a const view of a const vector, the view may not point to a different vector and the vector may not change.const ovector_view
is a const view of a normal vector, the view may not change, but the vector can. This same distinction is also present, for example, in ublas vectors views within boost.A reference of type ovector_base is often used as a function argument, and can hold either a ovector or a ovector_view. The important rule to remember with ovector_base is that, a const reference, i.e.
const ovector_base &v;
permutation p(4); p.init(); gsl_permutation_swap(&p,2,3);
The functions which apply a permutation to a user-specified vector are member template functions in the permutation class (see permutation::apply() ).
Memory allocation/deallocation between the class and the gsl_struct is compatible in many cases, but mixing these forms is strongly discouraged, i.e. avoid using gsl_permutation_alloc()
on a permutation object, but rather use permutation::allocate() instead. The use of permutation::free() is encouraged, but any remaining memory will be deallocated in the object destructor.
operator
[], the BLAS and linear algebra routines are inside the o2scl_cblas and o2scl_linalg namespaces. For vector and matrix types using operator()
, the BLAS and linear algebra routines routines are inside the o2scl_cblas_paren and o2scl_linalg_paren namespaces.The linear algebra classes and functions include:
There is also a set of linear solvers for generic matrix and vector types which descend from o2scl_linalg::linear_solver. These classes provide GSL-like solvers, but are generalized so that they are compatible with vector and matrix types which allow access through operator[]
.
For users who require high-performance linear algebra, the ovector and omatrix objects can be used to call LAPACK routines directly, just as can be done with GSL. For an example of how to do this, see http://sourceware.org/ml/gsl-discuss/2001/msg00326.html .
Finally, there are also a couple of examples, gesvd.cpp
and zheev.cpp
in the src/internal
directory which show how to call LAPACK with O2scl objects which may be adaptable for your platform and configuration.
For fast interpolation of arrays where the independent variable is strictly increasing and without error-checking, you can directly use the children of base_interp.
gsl_interp_eval()
and gsl_spline_eval()
in GSL
. You can create a o2scl_interp object and use it to interpolate among any pair of chosen vectors, i.e. ovector x(20), y(20); // fill x and y with data o2scl_interp oi; double y_half=oi.interp(0.5,20,x,y);
ovector x(20), y(20); // fill x and y with data o2scl_interp_vec oi(20,x,y); double y_half=oi.interp(0.5);
For an example usage of the default interpolation manager, see the Contour lines example , which specifies an interpolation manager for the contour class. The table class also works with interpolation manager objects (see table::set_interp() ).
const
double
and placed in namespaces called gsl_cgs, gsl_cgsm, gsl_mks, gsl_mksa, and gsl_num. Some additional constants are given in the namespace o2scl_const. Some of the numerical values have been updated from recently released data from NIST.
n
functions of n
variablesn
fitting parametersn
derivatives as a function of n
function values and the value of the independent variable
For each of these classes (except funct), there is a version named _vfunct
instead of _funct
which is designed to be used with C-style arrays instead of vector classes.
The class name suffixes denote children of a generic function type which are created using different kinds of inputs:
See the Function and solver example and the Multi-dimensional solver example which provide detailed examples of how functions can be specified to classes through these function objects.
There is a small overhead associated with the indirection: a "user class" accesses the function class which then calls function which was specified in the constructor of the function class. In many problems, the overhead associated with the indirection is small. Some of this overhead can always be avoided by inheriting directly from the function class and thus the user class will make a direct virtual function call. To eliminate the overhead entirely, one can specify a new type for the template parameter in the user class.
Note that virtual functions can be specified through this mechanism as well. For example, if cern_mroot is used to solve a set of equations specified as
class my_type_t { virtual member_func(); }; my_type_t my_instance; class my_derived_type_t : public my_type_t { virtual member_func(); }; my_derived_type_t my_inst2; mm_funct_mfptr<my_type_t> func(&my_inst2,&my_instance::member_func);
Note also that providing a user access to a function object instantiatied with a protected or private member function is (basically) the same as providing them access to that function.
std::string
objects are given in string_conv.h and includeSee also size_of_exponent(), format_float, and double_to_ieee_string().
A class called columnify converts a set of strings into nicely formatted columns by padding with the necessary amount of spaces. This class operates on string objects of type std::string
, and also works will for formatting columns of floating-point numbers. This class is used to provide output for matrices in the functions matrix_out(), matrix_out_paren(), and matrix_cx_out_paren(). For output of vectors, see vector_out() in array.h.
A related function, screenify(), reformats a column of strings into many columns stored row-by-row in a new string array. It operates very similar to the way the classic Unix command ls
organizes files and directories in multiple columns in order to save screen space.
The function count_words() counts the number of "words" in a string, which are delimited by whitespace.
Warning: For gsl_deriv and cern_deriv, the second and third derivatives are calculated by naive repeated application of the code for the first derivative and can be particularly troublesome if the function is not sufficiently smooth. Error estimation is not provided for second and third derivatives.
o2scl_inte
.There are several routines for one-dimensional integration.
cos(x)
or sin(x)
: gsl_inte_qawo_cos and gsl_inte_qawo_sin
is performed by gsl_inte_qaws.
For the GSL-based integration routines, the variables inte::tolx and inte::tolf have the same role as the quantities usually denoted in the GSL integration routines by epsabs
and epsrel
. In particular, the integration classes attempt to ensure that
and returns an error to attempt to ensure that
where I
is the integral to be evaluated. Even when the corresponding descendant of inte::integ() returns success, these inequalities may fail for sufficiently difficult functions. All of the GSL integration routines except for gsl_inte_qng use a workspace given in gsl_inte_table which holds the results of the various subdivisions of the original interval. The size of this workspace (and thus then number of subdivisions) can be controlled with gsl_inte_table::set_wkspace().
The GSL routines were originally based on QUADPACK, which is available at http://www.netlib.org/quadpack .
General multi-dimensional integration is performed by comp_gen_inte, the sole descendant of gen_inte. The user is allowed to specify a upper and lower limits which are functions of the variables for integrations which have not yet been performed, i.e. the n-dimensional integral
Again, one specifies a set of inte objects to apply to each variable to be integrated over.
Monte Carlo integration is also provided (see Monte Carlo Integration).
_real
(quadratic_real, cubic_real and quartic_real), classes which handle real coefficients and complex roots end with the suffix _real_coeff
(quadratic_real_coeff, cubic_real_coeff, quartic_real_coeff, and poly_real_coeff), and classes which handle complex polynomials with complex coefficients end with the suffix _complex
(quadratic_complex, cubic_complex, quartic_complex, and poly_complex). As a reminder, complex roots may not occur in conjugate pairs if the coefficients are not real. Most of these routines will return an error if the leading coefficient is zero.
In the public interfaces to the polynomial solvers, the complex type std::complex<double>
is used. These can be converted to and from the GSL complex type using the complex_to_gsl() and gsl_to_complex() functions.
At present, the polynomial routines work with complex numbers as objects of type std::complex<double>
and are located in library o2scl_other
.
For quadratics, gsl_quadratic_real_coeff is the best if the coefficients are real, while if the coefficients are complex, use quadratic_std_complex. For cubics with real coefficients, cern_cubic_real_coeff is the best, while if the coefficients are complex, use cubic_std_complex.
For a quartic polynomial with real coefficients, cern_quartic_real_coeff is the best, unless the coefficients of odd powers happen to be small, in which case, gsl_quartic_real2 tends to work better. For quartics, generic polynomial solvers such as gsl_poly_real_coeff can provide more accurate (but slower) results. If the coefficients are complex, then you can use simple_quartic_complex.
For one-dimensional solving, use cern_root or gsl_root_brent if you have the root bracketed, or gsl_root_stef if you have the derivative available. If you have neither a bracket or a derivative, you can use cern_mroot_root.
The root base class provides the structure for three different solving methods:
x
x1
and x2
. The values of the function at x1
and x2
should have different signs.x
and the derivative of the function df
.If not all of these three functions are overloaded, then the source code in the root base class is designed to try to automatically provide the solution using the remaining functions. Most of the one-dimensional solving routines, in their original form, are written in the second or third form above. For example, gsl_root_brent is originally a bracketing routine of the form root::solve_bkt(), but calls to either root::solve() or root::solve_de() will attempt to automatically bracket the function given the initial guess that is provided. Of course, it is frequently most efficient to use the solver in the way it was intended.
For multi-dimensional solving, you can use either cern_mroot or gsl_mroot_hybrids. While cern_mroot cannot utilize user-supplied derivatives, gsl_mroot_hybrids can use user-supplied derivative information (as in the GSL hybridsj method) using the function gsl_mroot_hybrids::msolve_de() .
Multi-dimensional minimization is performed by descendants of multi_min: gsl_mmin_simp2, gsl_mmin_conp, gsl_mmin_conf, and gsl_mmin_bfgs2. (The class gsl_mmin_simp2 has been updated with the new "simplex2" method from GSL-1.12. The older "simplex" method is also available in gsl_mmin_simp .) The classes gsl_mmin_simp and gsl_mmin_simp2 do not require any derivative information. The remaining minimization classes are intended for use when the gradient of the function is available, but they can also automaticallly compute the gradient numerically. The standard way to provide the gradient is to use a child of grad_funct (or grad_vfunct). Finally, the user may specify the automatic gradient object of type gradient (or gradient_array) which is used by the minimizer to compute the gradient numerically when a function is not specified.
See an example for the usage of the multi-dimensional minimizers in Multidimensional minimizer example .
Simulated annealing methods are also provided for multi-dimensional minimization (see Simulated Annealing).
It is important to note that not all of the minimization routines test the second derivative to ensure that it doesn't vanish to ensure that we have indeed found a true minimum.
The class multi_min_fix provides a convenient way of fixing some of the parameters and minimizing over others, without requiring a the function interface to be rewritten. An example is given in Minimizer fixing variables example.
The constrained minimization classes operate in a similar way to the other multi-dimensional minimization classes (which are derived from multi_min). The constraints are specified with the function
ool_constr_mmin::set_constraints(size_t nc, vec_t &lower, vec_t &upper);
There are five error codes defined in ool_constr_mmin which are specific to the classes derived from OOL.
The class gsl_anneal can handle some kinds of constraints by ignoring proposed steps which cause the user-specified function to return a non-zero value.
Also, a simple way of implementing constraints is to add a function to the original which increases the value outside of the allowed region. This can be done with the functions constraint() and lower_bound(). There are two analogous functions, cont_constraint() and cont_lower_bound(), which continuous and differentiable versions. Where possible, it is better to use the constrained minimization routines described below.
Solution of simple initial value problems is performed by ode_iv_solve. This class contains a couple different methods, depending on whether the user needs only the final value or the solution on a fixed grid. A example demonstrating the solution of initial value problems is given in Ordinary differential equations example.
The solution of boundary-value problems is based on the abstract base class ode_bv_solve. At the moment, a simple shooting method is the only implementation of this base class and is given in ode_bv_shoot . An experimental multishooting class is given in ode_bv_multishoot .
An application of linear solvers to solve finite-difference equations approximating a boundary value problem is given in ode_it_solve . A example demonstrating the iterative solution of a boundary value problem is given in Iterative solution of ODEs example .
If data is arranged without a grid, then planar_intp can be used. At present, the only way to compute contour lines on data which is not defined on a grid is to use planar_intp to recast the data on a grid and then use contour afterwards.
Higher-dimensional interpolation is possible with tensor_grid.
Three-dimensional data tables - table3d
Series acceleration - gsl_series
Command-line interface - cli
Automatic bin sizing - bin_size
Fourier transforms - gsl_fft
Polylogarithms - polylog
There are several data files that are used by various classes in the library. The installation procedure should ensure that these files are automatically found. However, if these data files are moved after installation, then a call to lib_settings_class::set_data_dir() can adjust the library to use the new directory. It is assumed that the directory structure within the data directory has not changed.
Collections of objects can be stored in a collection class, and these collections can be written to or read from text or binary files. User-defined classes may be added to the collections and may be read and written to files as long as a descendant of io_base is provided.
Every type has an associated I/O type which is a descendant of io_base. In order to perform any sort of input/output on any type, an object of the corresponding I/O type must be instantiated by the user. This is not done automatically by the library. (Since it doesn't know which objects are going to be used ahead of time, the library would have to instantiate all of the I/O objects, which is needlessly slow.) This makes the I/O slightly less user-friendly, but much more efficient. For convenience, each subsection of the library has a class (named with an _ioc
suffix) which will automatically allocate all I/O types for that subsection.
Level 1 functions: Functions that input/output data from library-defined objects and internal types from files and combine these objects in collections. These are primarily member functions of the class collection.
Level 2 functions: Functions which are designed to allow the user to input or output data for user-generated objects. These are primarily member functions of classes cinput and coutput.
Level 3 functions: Functions which allow low-level modifications on how input and output is performed. Usage of level 3 functions is not immediately recommended for the casual user.
Level 1 usage:
For adding an object to a collection when you have a pointer to the I/O object for the associated type:
int collection::add(std::string name, io_base *tio, void *vec, int sz=0, int sz2=0, bool overwrt=true, bool owner=false);
int collection::add(std::string name, std::string stype, void *vec, int sz=0, int sz2=0, bool overwrt=true, bool owner=false);
To retrieve an object as a
void *from a collection use one of:
int get(std::string tname, void *&vec); int get(std::string tname, void *&vec, int &sz); int get(std::string tname, void *&vec, int &sz, int &sz2); int get(std::string tname, std::string &stype, void *&vec); int get(std::string tname, std::string &stype, void *&vec, int &sz); int get(std::string tname, std::string &stype, void *&vec, int &sz, int &sz2);
void *get(std::string name);
To output one object to a file:
int collection::out_one(out_file_format *outs, std::string stype, std::string name, void *vp, int sz=0, int sz2=0);
To input one object from a file with a given type and name:
int collection::in_one_name(in_file_format *ins, std::string stype, std::string name, void *&vp, int &sz, int &sz2);
int collection::in_one(in_file_format *ins, std::string stype, std::string &name, void *&vp, int &sz, int &sz2);
Level 2 usage (string-based):
If you don't have a pointer to the io_base child object corresponding to the type of subobject that you are manipulating, then you can use the following functions, which take the type name as a string.
To input a sub-object in an io_base template for which memory has already been allocated use one of:
int collection::object_in(std::string type, in_file_format *ins, void *vp, std::string &name); int collection::object_in(std::string type, in_file_format *ins, void *vp, int sz, std::string &name); int collection::object_in(std::string type, in_file_format *ins, void *vp, int sz, int sz2, std::string &name);
To automatically allocate memory and input a sub-object of a io_base template use one of:
int collection::object_in_mem(std::string type, in_file_format *ins, void *vp, std::string &name); int collection::object_in_mem(std::string type, in_file_format *ins, void *vp, int sz, std::string &name); int collection::object_in_mem(std::string type, in_file_format *ins, void *vp, int sz, int sz2, std::string &name);
To output a subobject in an io_base template use:
int collection::object_out(std::string type, out_file_format *outs, void *op, int sz=0, int sz2=0, std::string name="");
Level 2 usage (with io_base pointer):
To input a sub-object in an io_base template for which memory has already been allocated use one of:
virtual int object_in(cinput *cin, in_file_format *ins, object *op, std::string &name); virtual int object_in(cinput *cin, in_file_format *ins, object *op, int sz, std::string &name); virtual int object_in(cinput *cin, in_file_format *ins, object **op, int sz, int sz2, std::string &name); template<size_t N> int object_in(cinput *co, in_file_format *ins, object op[][N], int sz, std::string &name);
To automatically allocate memory and input a sub-object of a io_base template use one of:
virtual int object_in_mem(cinput *cin, in_file_format *ins, object *&op, std::string &name); virtual int object_in_mem(cinput *cin, in_file_format *ins, object *&op, int &sz, std::string &name); virtual int object_in_mem(cinput *cin, in_file_format *ins, object **&op, int &sz, int &sz2, std::string &name); template<size_t N> int object_in_mem(cinput *co, in_file_format *ins, object op[][N], int &sz, std::string &name);
To output a subobject in an io_base template use:
virtual int object_out(coutput *cout, out_file_format *outs, object *op, int sz=0, std::string name=""); virtual int object_out(coutput *cout, out_file_format *outs, object **op, int sz, int sz2, std::string name=""); template<size_t N> int object_out(coutput *cout, out_file_format *outs, object op[][N], int sz, std::string name="");
To automatically allocate/deallocate memory for an object, use:
virtual int mem_alloc(object *&op); virtual int mem_alloc_arr(object *&op, int sz); virtual int mem_alloc_2darr(object **&op, int sz, int sz2); virtual int mem_free(object *op); virtual int mem_free_arr(object *op); virtual int mem_free_2darr(object **op, int sz);
Where and
. The parameter
is stored as member data for the class, and the parameter
is an argument to the member function.
The image below shows how the solver progresses to the solution of the example function.
ex_fptr.png
/* Example: ex_fptr.cpp ------------------------------------------------------------------- This gives an example of the how member functions and external parameters are supplied to numerical routines. In this case, a member function with two parameters is passed to the gsl_root_brent class, which solves the equation. One of the parameters is member data, and the other is specified using the extra parameter argument to the function. */ #include <o2scl/funct.h> #include <o2scl/gsl_root_brent.h> #include <o2scl/test_mgr.h> using namespace std; using namespace o2scl; class my_class { private: double parameter; public: void set_parameter() { parameter=0.01; } // A function demonstrating the different ways of implementing // function parameters double function_to_solve(double x, double &p) { return atan((x-parameter)*4)*(1.0+sin((x-parameter)*50.0)/p); } }; // Simple code to write the function to a file int write_file(double sol); int main(void) { cout.setf(ios::scientific); test_mgr t; // Only print something out if one of the tests fails t.set_output_level(1); // The solver, specifying the type of the parameter (double) // and the function type (funct<double>) gsl_root_brent<double,funct<double> > solver; my_class c; c.set_parameter(); // This is the code that allows specification of class member // functions as functions to solve. This approach avoids the use of // static variables and functions and multiple inheritance at the // expense of a little overhead. We need to provide the address of // an instantiated object and the address of the member function. funct_mfptr_noerr<my_class,double> function(&c,&my_class::function_to_solve); double x1=-1; double x2=2; double p=1.1; // The value verbose=1 prints out iteration information // and verbose=2 requires a keypress between iterations. // The parameter p=0.1 is used. solver.verbose=1; solver.solve_bkt(x1,x2,p,function); // This is actually a somewhat difficult function to solve because // of the sinusoidal behavior. cout << "Solution: " << x1 << " Function value: " << c.function_to_solve(x1,p) << endl; // Write the function being solved to a file (see source code // in examples directory for details) write_file(x1); t.report(); return 0; } // End of example
/* Example: ex_mroot.cpp ------------------------------------------------------------------- Several ways to use an O2scl solver to solve a simple function */ #include <cmath> #include <o2scl/test_mgr.h> #include <o2scl/mm_funct.h> #include <o2scl/gsl_mroot_hybrids.h> #include <o2scl/cern_mroot.h> using namespace std; using namespace o2scl; int gfn(size_t nv, const ovector_base &x, ovector_base &y, int &pa) { y[0]=sin(x[1]-0.2); y[1]=sin(x[0]-0.25); return 0; } class cl { public: // Store the number of function and derivative evaluations int nf, nd; int mfn(size_t nv, const ovector_base &x, ovector_base &y, int &pa) { y[0]=sin(x[1]-0.2); y[1]=sin(x[0]-0.25); nf++; return 0; } int operator()(size_t nv, const ovector_base &x, ovector_base &y, int &pa) { y[0]=sin(x[1]-0.2); y[1]=sin(x[0]-0.25); nf++; return 0; } int mfnd(size_t nv, ovector_base &x, ovector_base &y, omatrix_base &j, int &pa) { j[0][0]=0.0; j[0][1]=cos(x[1]-0.2); j[1][0]=cos(x[0]-0.25); j[1][1]=0.0; nd++; return 0; } int mfna(size_t nv, const double x[2], double y[2], int &pa) { y[0]=sin(x[1]-0.2); y[1]=sin(x[0]-0.25); return 0; } int mfnad(size_t nv, double x[], double y[], double j[2][2], int &pa) { j[0][0]=0.0; j[0][1]=cos(x[1]-0.2); j[1][0]=cos(x[0]-0.25); j[1][1]=0.0; return 0; } }; int main(void) { cl acl; ovector x(2); double xa[2]; int i; int vp=0; size_t tmp; int r1, r2, r3; bool done; test_mgr t; t.set_output_level(1); /* Using a member function with \ref ovector objects */ mm_funct_mfptr<cl,int,ovector_base> f1(&acl,&cl::mfn); gsl_mroot_hybrids<int> cr1; x[0]=0.5; x[1]=0.5; acl.nf=0; int ret1=cr1.msolve(2,x,vp,f1); cout << "GSL solver (numerical Jacobian): " << endl; cout << "Return value: " << ret1 << endl; cout << "Number of iterations: " << cr1.last_ntrial << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(x[0],0.25,1.0e-6,"1a"); t.test_rel(x[1],0.2,1.0e-6,"1b"); /* Using the CERNLIB solver */ cern_mroot<int> cr2; x[0]=0.5; x[1]=0.5; acl.nf=0; int ret2=cr2.msolve(2,x,vp,f1); cout << "CERNLIB solver (numerical Jacobian): " << endl; cout << "Return value: " << ret2 << endl; cout << "INFO parameter: " << cr2.get_info() << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(x[0],0.25,1.0e-6,"2a"); t.test_rel(x[1],0.2,1.0e-6,"2b"); /* Using a member function with \ref ovector objects, but using the GSL-like interface with set() and iterate(). */ gsl_mroot_hybrids<int> cr3; x[0]=0.5; x[1]=0.5; cr3.allocate(2); cr3.set(2,x,f1,vp); done=false; do { r3=cr3.iterate(); double resid=fabs(cr3.f[0])+fabs(cr3.f[1]); if (resid<cr3.tolf || r3>0) done=true; } while (done==false); t.test_rel(cr3.x[0],0.25,1.0e-6,"3a"); t.test_rel(cr3.x[1],0.2,1.0e-6,"3b"); cr3.free(); /* Now instead of using the automatic Jacobian, using a user-specified Jacobian. */ jac_funct_mfptr<cl,int,ovector_base,omatrix_base> j4(&acl,&cl::mfnd); x[0]=0.5; x[1]=0.5; acl.nf=0; acl.nd=0; int ret4=cr1.msolve_de(2,x,vp,f1,j4); cout << "GSL solver (analytic Jacobian): " << endl; cout << "Return value: " << ret4 << endl; cout << "Number of iterations: " << cr1.last_ntrial << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << "Number of Jacobian evaluations: " << acl.nd << endl; cout << endl; t.test_rel(x[0],0.25,1.0e-6,"4a"); t.test_rel(x[1],0.2,1.0e-6,"4b"); /* Using a user-specified Jacobian and the GSL-like interface */ gsl_mroot_hybrids<int> cr5; x[0]=0.5; x[1]=0.5; cr5.allocate(2); cr5.set_de(2,x,f1,j4,vp); done=false; do { r3=cr5.iterate(); double resid=fabs(cr5.f[0])+fabs(cr5.f[1]); if (resid<cr5.tolf || r3>0) done=true; } while (done==false); t.test_rel(cr5.x[0],0.25,1.0e-6,"5a"); t.test_rel(cr5.x[1],0.2,1.0e-6,"5b"); cr5.free(); /* Using C-style arrays instead of ovector objects */ mm_vfunct_mfptr<cl,int,2> f6(&acl,&cl::mfna); gsl_mroot_hybrids<int,mm_vfunct_mfptr<cl,int,2>,double[2], double[2],array_alloc<double[2]> > cr6; xa[0]=0.5; xa[1]=0.5; cr6.msolve(2,xa,vp,f6); t.test_rel(xa[0],0.25,1.0e-6,"6a"); t.test_rel(xa[1],0.2,1.0e-6,"6b"); /* Using the CERNLIB solver with C-style arrays instead of ovector objects */ cern_mroot<int,mm_vfunct_mfptr<cl,int,2>,double[2], double[2],array_alloc<double[2]> > cr7; xa[0]=0.5; xa[1]=0.5; cr7.msolve(2,xa,vp,f6); t.test_rel(xa[0],0.25,1.0e-6,"7a"); t.test_rel(xa[1],0.2,1.0e-6,"7b"); /* Using C-style arrays with a user-specified Jacobian */ jac_vfunct_mfptr<cl,int,2> j8(&acl,&cl::mfnad); gsl_mroot_hybrids<int,mm_vfunct_mfptr<cl,int,2>,double[2], double[2],array_alloc<double[2]>,double[2][2],double[2][2], array_2d_alloc<double[2][2]>,jac_vfunct<int,2> > cr8; xa[0]=0.5; xa[1]=0.5; cr8.msolve_de(2,xa,vp,f6,j8); t.test_rel(xa[0],0.25,1.0e-6,"8a"); t.test_rel(xa[1],0.2,1.0e-6,"8b"); /* Using a class with an operator(). Note that there can be only one operator() function in each class. */ gsl_mroot_hybrids<int,cl,ovector_base> cr9; x[0]=0.5; x[1]=0.5; cr9.msolve(2,x,vp,acl); t.test_rel(x[0],0.25,1.0e-6,"9a"); t.test_rel(x[1],0.2,1.0e-6,"9b"); /* Using a function pointer to a global function. */ typedef int (*gfnt)(size_t, const ovector_base &, ovector_base &, int &); gsl_mroot_hybrids<int,gfnt,ovector_base> cr10; gfnt f10=&gfn; x[0]=0.5; x[1]=0.5; cr10.msolve(2,x,vp,f10); t.test_rel(x[0],0.25,1.0e-6,"10a"); t.test_rel(x[1],0.2,1.0e-6,"10b"); t.report(); return 0; } // End of example
/* Example: ex_mmin.cpp ------------------------------------------------------------------- Example usage of the multidimensional minimizers */ #include <cmath> #include <o2scl/test_mgr.h> #include <o2scl/multi_funct.h> #include <o2scl/gsl_mmin_simp2.h> #include <o2scl/gsl_mmin_conf.h> #include <o2scl/gsl_mmin_conp.h> #include <o2scl/gsl_mmin_bfgs2.h> using namespace std; using namespace o2scl; class cl { public: int mfn(size_t nv, const ovector_base &x, double &y, int &pa) { y=(x[0]-2.0)*(x[0]-2.0)+(x[1]-1.0)*(x[1]-1.0); return 0; } }; int main(void) { cl acl; ovector x(2); int vp=0; double fmin; test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); /** Using a member function with \ref ovector objects */ multi_funct_mfptr<cl,int,ovector_base> f1(&acl,&cl::mfn); gsl_mmin_simp2<int> gm1; gsl_mmin_conf<int> gm2; gsl_mmin_conp<int> gm3; gsl_mmin_bfgs2<int> gm4; x[0]=0.5; x[1]=0.5; gm1.mmin(2,x,fmin,vp,f1); cout << gm1.last_ntrial << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"1a"); t.test_rel(x[1],1.0,1.0e-4,"1b"); x[0]=0.5; x[1]=0.5; gm2.mmin(2,x,fmin,vp,f1); cout << gm2.last_ntrial << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"2a"); t.test_rel(x[1],1.0,1.0e-4,"2b"); x[0]=0.5; x[1]=0.5; gm3.mmin(2,x,fmin,vp,f1); cout << gm3.last_ntrial << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"3a"); t.test_rel(x[1],1.0,1.0e-4,"3b"); x[0]=0.5; x[1]=0.5; gm4.err_nonconv=false; gm4.mmin(2,x,fmin,vp,f1); cout << gm4.last_ntrial << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"4a"); t.test_rel(x[1],1.0,1.0e-4,"4b"); t.report(); return 0; } // End of example
while fixing some of the parameters.
/* Example: ex_mmin_fix.cpp ------------------------------------------------------------------- Example usage of the mmin_fix class, which fixes some of the paramters for a multidimensional minimization. */ #include <cmath> #include <o2scl/test_mgr.h> #include <o2scl/multi_funct.h> #include <o2scl/gsl_mmin_simp2.h> #include <o2scl/multi_min_fix.h> using namespace std; using namespace o2scl; class cl { public: int mfn(size_t nv, const ovector_base &x, double &y, int &pa) { y=(x[0]-2.0)*(x[0]-2.0)+(x[1]-1.0)*(x[1]-1.0)+x[2]*x[2]; return 0; } }; int main(void) { cl acl; ovector x(3); int vp=0; double fmin; test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); /* Perform the minimization the standard way, with the simplex2 minimizer */ multi_funct_mfptr<cl,int,ovector_base> f1(&acl,&cl::mfn); gsl_mmin_simp2<int> gm1; x[0]=0.5; x[1]=0.5; x[2]=0.5; gm1.mmin(3,x,fmin,vp,f1); cout << gm1.last_ntrial << " iterations." << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"1a"); t.test_rel(x[1],1.0,1.0e-4,"1b"); t.test_rel(x[2],0.0,1.0e-4,"1c"); // Create a new multi_min_fix object multi_min_fix<int,bool[3]> gmf; // Create a base minimizer which can be used by the multi_min_fix // object. Note that we can't use 'gm1' here, because it has a // different type than 'gm2', even though its functionality is // effectively the same. gsl_mmin_simp2<int,multi_funct_mfptr <multi_min_fix<int,bool[3]>,int> > gm2; // Set the base minimizer gmf.set_mmin(gm2); /* First perform the minimization as above. */ x[0]=0.5; x[1]=0.5; x[2]=0.5; gmf.mmin(3,x,fmin,vp,f1); cout << gmf.last_ntrial << " iterations." << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"2a"); t.test_rel(x[1],1.0,1.0e-4,"2b"); t.test_rel(x[2],0.0,1.0e-4,"2c"); /* Now fix the 2nd variable, and re-minimize. */ bool fix[3]={false,true,false}; x[0]=0.5; x[1]=0.5; x[2]=0.5; gmf.mmin_fix(3,x,fmin,fix,vp,f1); cout << gmf.last_ntrial << " iterations." << endl; cout << "Found minimum at: " << x << endl; t.test_rel(x[0],2.0,1.0e-4,"3a"); t.test_rel(x[1],0.5,1.0e-4,"3b"); t.test_rel(x[2],0.0,1.0e-4,"3c"); t.report(); return 0; } // End of example
/* Example: ex_deriv.cpp ------------------------------------------------------------------- An example to demonstrate numerical differentiation */ #include <cmath> #include <o2scl/test_mgr.h> #include <o2scl/funct.h> #include <o2scl/gsl_deriv.h> #include <o2scl/cern_deriv.h> using namespace std; using namespace o2scl; class cl { public: // This is the function we'll take the derivative of double function(double x) { return sin(2.0*x)+0.5; } }; int main(void) { cl acl; ovector x(2); double xa[2]; int i; int vp=0; size_t tmp; int r1, r2, r3; bool done; test_mgr t; t.set_output_level(2); funct_mfptr_nopar<cl,int> f1(&acl,&cl::function); gsl_deriv<int> gd; // Note that the GSL derivative routine requires an initial stepsize gd.h=1.0e-3; cern_deriv<int> cd; // Compute the first derivative using the gsl_deriv class and // verify that the answer is correct double d1=gd.calc(1.0,vp,f1); t.test_rel(d1,2.0*cos(2.0),1.0e-10,"gsl_deriv"); // Compute the first derivative using the cern_deriv class and // verify that the answer is correct double d2=cd.calc(1.0,vp,f1); t.test_rel(d2,2.0*cos(2.0),1.0e-10,"cern_deriv"); // Compute the second derivative also double d3=gd.calc2(1.0,vp,f1); t.test_rel(d3,-4.0*sin(2.0),5.0e-7,"gsl_deriv"); double d4=cd.calc2(1.0,vp,f1); t.test_rel(d4,-4.0*sin(2.0),1.0e-8,"cern_deriv"); t.report(); return 0; } // End of example
and compares the computed results with the exact results.
/* Example: ex_inte.cpp ------------------------------------------------------------------- An example to demonstrate numerical integration. */ #include <cmath> #include <o2scl/test_mgr.h> #include <o2scl/constants.h> #include <o2scl/funct.h> #include <o2scl/gsl_inte_qag.h> #include <o2scl/gsl_inte_qagi.h> #include <o2scl/gsl_inte_qagiu.h> #include <o2scl/gsl_inte_qagil.h> #include <o2scl/cern_adapt.h> using namespace std; using namespace o2scl; using namespace o2scl_const; class cl { public: // We'll use this to count the number of function // evaulations required by the integration routines int nf; // A function to be integrated double integrand(double x) { nf++; return exp(-x*x); } // Another function to be integrated double integrand2(double x) { nf++; return sin(2.0*x)+0.5; } }; int main(void) { cl acl; int vp=0; test_mgr t; t.set_output_level(1); funct_mfptr_nopar<cl,int> f1(&acl,&cl::integrand); funct_mfptr_nopar<cl,int> f2(&acl,&cl::integrand2); // We don't need to specify the function type in the integration // objects, because we're using the default function type (type // funct). gsl_inte_qag<int> g; gsl_inte_qagi<int> gi; gsl_inte_qagiu<int> gu; gsl_inte_qagil<int> gl; cern_adapt<int> ca; // The result and the uncertainty double res, err; // An integral from -infinity to +infinity (the limits are ignored) acl.nf=0; int ret1=gi.integ_err(f1,0.0,0.0,vp,res,err); cout << "gsl_inte_qagi: " << endl; cout << "Return value: " << ret1 << endl; cout << "Result: " << res << " Uncertainty: " << err << endl; cout << "Number of iterations: " << gi.last_iter << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(res,sqrt(pi),1.0e-8,"inte 1"); // An integral from 0 to +infinity (the second limit argument is // ignored in the line below) acl.nf=0; gu.integ_err(f1,0.0,0.0,vp,res,err); cout << "gsl_inte_qagiu: " << endl; cout << "Return value: " << ret1 << endl; cout << "Result: " << res << " Uncertainty: " << err << endl; cout << "Number of iterations: " << gu.last_iter << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(res,sqrt(pi)/2.0,1.0e-8,"inte 2"); // An integral from -infinity to zero (the first limit argument is // ignored in the line below) acl.nf=0; gl.integ_err(f1,0.0,0.0,vp,res,err); cout << "gsl_inte_qagil: " << endl; cout << "Return value: " << ret1 << endl; cout << "Result: " << res << " Uncertainty: " << err << endl; cout << "Number of iterations: " << gl.last_iter << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(res,sqrt(pi)/2.0,1.0e-8,"inte 3"); // An integral from 0 to 1 acl.nf=0; g.integ_err(f2,0.0,1.0,vp,res,err); cout << "gsl_inte_qag: " << endl; cout << "Return value: " << ret1 << endl; cout << "Result: " << res << " Uncertainty: " << err << endl; cout << "Number of iterations: " << g.last_iter << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(res,0.5+sin(1.0)*sin(1.0),1.0e-8,"inte 4"); // An integral from 0 to 1 acl.nf=0; ca.integ_err(f2,0.0,1.0,vp,res,err); cout << "cern_adapt: " << endl; cout << "Return value: " << ret1 << endl; cout << "Result: " << res << " Uncertainty: " << err << endl; cout << "Number of iterations: " << ca.last_iter << endl; cout << "Number of function evaluations: " << acl.nf << endl; cout << endl; t.test_rel(res,0.5+sin(1.0)*sin(1.0),1.0e-8,"inte 5"); t.report(); return 0; } // End of example
The Bessel functions are defined by
The Bessel functions of the first kind, are finite at the origin, and the example solves the
case, where
and
.
The Airy functions are defined by
This example solves for the Airy function of the first kind, .
Note that, when the step size is fixed, the Bessel function example is one case where the Prince-Dormand stepper (even though of higher order than the Cash-Karp stepper) is actually less accurate!
/* Example: ex_ode.cpp ------------------------------------------------------------------- An example to demonstrate solving differential equations */ #include <gsl/gsl_sf_bessel.h> #include <gsl/gsl_sf_airy.h> #include <gsl/gsl_sf_gamma.h> #include <o2scl/test_mgr.h> #include <o2scl/ovector_tlate.h> #include <o2scl/ode_funct.h> #include <o2scl/gsl_rkck.h> #include <o2scl/gsl_rk8pd.h> #include <o2scl/gsl_astep.h> #include <o2scl/ode_iv_solve.h> using namespace std; using namespace o2scl; // Differential equation defining the Bessel function. This assumes // the second derivative at x=0 is 0 and thus only works for odd alpha. int derivs(double x, size_t nv, const ovector_base &y, ovector_base &dydx, double &alpha) { dydx[0]=y[1]; if (x==0.0) dydx[1]=0.0; else dydx[1]=(-x*y[1]+(-x*x+alpha*alpha)*y[0])/x/x; return 0; } // Differential equation defining the Airy Ai(x) function. int derivs2(double x, size_t nv, const ovector_base &y, ovector_base &dydx, double &alpha) { dydx[0]=y[1]; dydx[1]=y[0]*x; return 0; } int main(void) { cout.setf(ios::scientific); cout.setf(ios::showpos); // The independent variable and stepsize double x, dx=1.0e-1; // The function and derivative values and the estimated errors ovector y(2), dydx(2), yout(2), yerr(2), dydx_out(2); test_mgr t; t.set_output_level(1); // Specify the differential equations to solve ode_funct_fptr<double,ovector_base> od(derivs); ode_funct_fptr<double,ovector_base> od2(derivs2); // The basic ODE steppers gsl_rkck<double> ode; gsl_rk8pd<double> ode2; // The parameter for the Bessel function double alpha=1.0; // ------------------------------------------------------------ // Solution 1: Solve using the non-adaptive Cash-Karp stepper. cout << "Bessel function, Cash-Karp: " << endl; // Initial values at x=0 x=0.0; y[0]=0.0; y[1]=0.5; // The non-adaptive ODE steppers require the derivatives as // input derivs(x,2,y,dydx,alpha); cout << " x J1(calc) J1(exact) rel. diff. " << "err" << endl; while (x<1.0) { // Perform a step. Since the fourth and sixth arguments are // the same, the values in 'y' are updated with the new values // at x+dx. ode.step(x,dx,2,y,dydx,y,yerr,dydx,alpha,od); // Update the x value x+=dx; // Print and test cout << x << " " << y[0] << " " << gsl_sf_bessel_J1(x) << " "; cout << fabs((y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x)) << " "; cout << yerr[0] << endl; t.test_rel(y[0],gsl_sf_bessel_J1(x),5.0e-5,"rkck"); } // Compare with the exact result at the last point cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x) << endl; cout << endl; // ------------------------------------------------------------ // Solution 2: Solve using the non-adaptive Prince-Dormand stepper. // Note that for the Bessel function, the 8th order stepper performs // worse than the 4th order. The error returned by the stepper is // larger near x=0, as expected. cout << "Bessel function, Prince-Dormand: " << endl; x=0.0; y[0]=0.0; y[1]=0.5; derivs(x,2,y,dydx,alpha); cout << " x J1(calc) J1(exact) rel. diff. " << "err" << endl; while (x<1.0) { ode2.step(x,dx,2,y,dydx,y,yerr,dydx,alpha,od); x+=dx; cout << x << " " << y[0] << " " << gsl_sf_bessel_J1(x) << " "; cout << fabs((y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x)) << " "; cout << yerr[0] << endl; t.test_rel(y[0],gsl_sf_bessel_J1(x),5.0e-4,"rk8pd"); } cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x) << endl; cout << endl; // ------------------------------------------------------------ // Solution 3: Solve using the non-adaptive Cash-Karp stepper. cout << "Airy function, Cash-Karp: " << endl; x=0.0; y[0]=1.0/pow(3.0,2.0/3.0)/gsl_sf_gamma(2.0/3.0); y[1]=-1.0/pow(3.0,1.0/3.0)/gsl_sf_gamma(1.0/3.0); derivs2(x,2,y,dydx,alpha); cout << " x Ai(calc) Ai(exact) rel. diff. " << "err" << endl; while (x<1.0) { ode.step(x,dx,2,y,dydx,y,yerr,dydx,alpha,od2); x+=dx; cout << x << " " << y[0] << " " << gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE) << " "; cout << fabs((y[0]-gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE))/ gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE)) << " "; cout << yerr[0] << endl; t.test_rel(y[0],gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE),1.0e-8,"rkck"); } cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE))/ gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE) << endl; cout << endl; // ------------------------------------------------------------ // Solution 4: Solve using the non-adaptive Prince-Dormand stepper. // On this function, the higher-order routine performs significantly // better. cout << "Airy function, Prince-Dormand: " << endl; x=0.0; y[0]=1.0/pow(3.0,2.0/3.0)/gsl_sf_gamma(2.0/3.0); y[1]=-1.0/pow(3.0,1.0/3.0)/gsl_sf_gamma(1.0/3.0); derivs2(x,2,y,dydx,alpha); cout << " x Ai(calc) Ai(exact) rel. diff. " << "err" << endl; while (x<1.0) { ode2.step(x,dx,2,y,dydx,y,yerr,dydx,alpha,od2); x+=dx; cout << x << " " << y[0] << " " << gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE) << " "; cout << fabs((y[0]-gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE))/ gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE)) << " "; cout << yerr[0] << endl; t.test_rel(y[0],gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE),1.0e-14,"rk8pd"); } cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE))/ gsl_sf_airy_Ai(x,GSL_PREC_DOUBLE) << endl; cout << endl; // ------------------------------------------------------------ // Solution 5: Solve using the GSL adaptive stepper // Lower the output precision to fit in 80 columns cout.precision(5); cout << "Adaptive stepper: " << endl; gsl_astep<double> ode3; x=0.0; y[0]=0.0; y[1]=0.5; cout << " x J1(calc) J1(exact) rel. diff."; cout << " err_0 err_1" << endl; int k=0; while (x<10.0) { int retx=ode3.astep(x,dx,10.0,2,y,dydx,yerr,alpha,od); if (k%3==0) { cout << retx << " " << x << " " << y[0] << " " << gsl_sf_bessel_J1(x) << " "; cout << fabs((y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x)) << " "; cout << yerr[0] << " " << yerr[1] << endl; } t.test_rel(y[0],gsl_sf_bessel_J1(x),5.0e-3,"astep"); t.test_rel(y[1],0.5*(gsl_sf_bessel_J0(x)-gsl_sf_bessel_Jn(2,x)), 5.0e-3,"astep 2"); t.test_rel(yerr[0],0.0,4.0e-6,"astep 3"); t.test_rel(yerr[1],0.0,4.0e-6,"astep 4"); t.test_gen(retx==0,"astep 5"); k++; } cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x) << endl; cout << endl; // ------------------------------------------------------------ // Solution 6: Solve using the GSL adaptive stepper. // Decrease the tolerances, and the adaptive stepper takes // smaller step sizes. cout << "Adaptive stepper with smaller tolerances: " << endl; ode3.con.eps_abs=1.0e-8; ode3.con.a_dydt=1.0; x=0.0; y[0]=0.0; y[1]=0.5; cout << " x J1(calc) J1(exact) rel. diff."; cout << " err_0 err_1" << endl; k=0; while (x<10.0) { int retx=ode3.astep(x,dx,10.0,2,y,dydx,yerr,alpha,od); if (k%3==0) { cout << retx << " " << x << " " << y[0] << " " << gsl_sf_bessel_J1(x) << " "; cout << fabs((y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x)) << " "; cout << yerr[0] << " " << yerr[1] << endl; } t.test_rel(y[0],gsl_sf_bessel_J1(x),5.0e-3,"astep"); t.test_rel(y[1],0.5*(gsl_sf_bessel_J0(x)-gsl_sf_bessel_Jn(2,x)), 5.0e-3,"astep 2"); t.test_rel(yerr[0],0.0,4.0e-8,"astep 3"); t.test_rel(yerr[1],0.0,4.0e-8,"astep 4"); t.test_gen(retx==0,"astep 5"); k++; } cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x) << endl; cout << endl; // ------------------------------------------------------------ // Solution 7: Solve using the GSL adaptive stepper. // Use the higher-order stepper, and less steps are required. The // stepper automatically takes more steps near x=0 in order since // the higher-order routine has more trouble there. cout << "Adaptive stepper, Prince-Dormand: " << endl; ode3.set_step(ode2); x=0.0; y[0]=0.0; y[1]=0.5; cout << " x J1(calc) J1(exact) rel. diff."; cout << " err_0 err_1" << endl; k=0; while (x<10.0) { int retx=ode3.astep(x,dx,10.0,2,y,dydx,yerr,alpha,od); if (k%3==0) { cout << retx << " " << x << " " << y[0] << " " << gsl_sf_bessel_J1(x) << " "; cout << fabs((y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x)) << " "; cout << yerr[0] << " " << yerr[1] << endl; } t.test_rel(y[0],gsl_sf_bessel_J1(x),5.0e-3,"astep"); t.test_rel(y[1],0.5*(gsl_sf_bessel_J0(x)-gsl_sf_bessel_Jn(2,x)), 5.0e-3,"astep"); t.test_rel(yerr[0],0.0,4.0e-8,"astep 3"); t.test_rel(yerr[1],0.0,4.0e-8,"astep 4"); t.test_gen(retx==0,"astep 5"); k++; } cout << "Accuracy at end: " << fabs(y[0]-gsl_sf_bessel_J1(x))/gsl_sf_bessel_J1(x) << endl; cout << endl; // ------------------------------------------------------------ // Solution 8: Solve using the O2scl initial value solver // Return the output precision to the default cout.precision(6); cout << "Initial value solver: " << endl; ode_iv_solve<double> ode4; const size_t ngrid=101; ovector xg(ngrid), yinit(2); omatrix yg(ngrid,2), ypg(ngrid,2); for(size_t i=0;i<ngrid;i++) xg[i]=((double)i)/10.0; yinit[0]=0.0; yinit[1]=0.5; ode4.solve_grid<omatrix,omatrix_row,omatrix_alloc> (0.0,10.0,0.1,2,yinit,ngrid,xg,yg,ypg,alpha,od); cout << " x J1(calc) J1(exact) rel. diff." << endl; for(size_t i=1;i<ngrid;i+=10) { cout << xg[i] << " " << yg[i][0] << " " << gsl_sf_bessel_J1(xg[i]) << " "; cout << fabs((yg[i][0]-gsl_sf_bessel_J1(xg[i]))/ gsl_sf_bessel_J1(xg[i])) << endl; t.test_rel(yg[i][0],gsl_sf_bessel_J1(xg[i]),5.0e-7,"astep"); t.test_rel(yg[i][1],0.5*(gsl_sf_bessel_J0(xg[i])- gsl_sf_bessel_Jn(2,xg[i])),5.0e-7,"astep 2"); } cout << "Accuracy at end: " << fabs(yg[ngrid-1][0]-gsl_sf_bessel_J1(xg[ngrid-1]))/ gsl_sf_bessel_J1(xg[ngrid-1]) << endl; cout << endl; cout.unsetf(ios::showpos); t.report(); return 0; } // End of example
which have the exact solution
using both the stiff stepper gsl_bsimp and the standard adaptive stepper gsl_astep . The adaptive stepper fails as becomes larger.
/* Example: ex_stiff.cpp ------------------------------------------------------------------- An example to demonstrate solving stiff differential equations */ #include <o2scl/test_mgr.h> #include <o2scl/ovector_tlate.h> #include <o2scl/funct.h> #include <o2scl/ode_funct.h> #include <o2scl/gsl_astep.h> #include <o2scl/gsl_bsimp.h> using namespace std; using namespace o2scl; int derivs(double x, size_t nv, const ovector_base &y, ovector_base &dydx, int &pa) { dydx[0]=480.0*y[0]+980.0*y[1]; dydx[1]=-490.0*y[0]-990.0*y[1]; return 0; } int jac(double x, size_t nv, const ovector_base &y, omatrix_base &dfdy, ovector_base &dfdx, int &pa) { dfdy[0][0]=480.0; dfdy[0][1]=980.0; dfdy[1][0]=-490.0; dfdy[1][1]=-990.0; dfdx[0]=0.0; dfdx[1]=0.0; return 0; } int main(void) { test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); cout.precision(3); int vp=0; // Specification of the differential equations and the Jacobian ode_funct_fptr<int,ovector_base> od(derivs); ode_jac_funct_fptr<int,ovector_base> oj(jac); // ------------------------------------------------------------ // First solve with gsl_bsimp, designed to handle stiff ODEs gsl_bsimp<int,ode_funct_fptr<int>,ode_jac_funct_fptr<int> > gb; double x1, dx=1.0e-1; ovector y1(2), dydx1(2), yout1(2), yerr1(2), dydx_out1(2); x1=0.0; y1[0]=1.0; y1[1]=0.0; derivs(x1,2,y1,dydx1,vp); for(size_t i=1;i<=40;i++) { gb.step(x1,dx,2,y1,dydx1,y1,yerr1,dydx1,vp,od,oj); x1+=dx; cout.setf(ios::showpos); cout << x1 << " " << y1 << " " << yerr1 << " " << -exp(-500.0*x1)+2.0*exp(-10.0*x1) << " " << exp(-500.0*x1)-exp(-10.0*x1) << endl; cout.unsetf(ios::showpos); t.test_rel(y1[0],-exp(-500.0*x1)+2.0*exp(-10.0*x1),3.0e-4,"y0"); t.test_rel(y1[1],exp(-500.0*x1)-exp(-10.0*x1),3.0e-4,"y1"); } cout << endl; // ------------------------------------------------------------ // Now compare to the traditional adaptive stepper gsl_astep<int,ode_funct_fptr<int> > ga; double x2; ovector y2(2), dydx2(2), yout2(2), yerr2(2), dydx_out2(2); x2=0.0; y2[0]=1.0; y2[1]=0.0; derivs(x2,2,y2,dydx2,vp); size_t j=0; while (x2<4.0) { ga.astep(x2,dx,4.0,2,y2,dydx2,yerr2,vp,od); if (j%25==0) { cout.setf(ios::showpos); cout << x2 << " " << y2 << " " << yerr2 << " " << -exp(-500.0*x2)+2.0*exp(-10.0*x2) << " " << exp(-500.0*x2)-exp(-10.0*x2) << endl; cout.unsetf(ios::showpos); } j++; } cout << endl; t.report(); return 0; } // End of example
/* Example: ex_anneal.cpp ------------------------------------------------------------------- An example to demonstrate minimization by simulated annealing */ #include <iostream> #include <cmath> #include <gsl/gsl_sf_bessel.h> #include <o2scl/ovector_tlate.h> #include <o2scl/multi_funct.h> #include <o2scl/funct.h> #include <o2scl/gsl_anneal.h> #include <o2scl/test_mgr.h> using namespace std; using namespace o2scl; // A simple function with many local minima. A "greedy" minimizer // would likely fail to find the correct minimum. double function(size_t nvar, const ovector_base &x, int &vp) { double a, b; a=(x[0]-2.0); b=(x[1]+3.0); return -gsl_sf_bessel_J0(a)*gsl_sf_bessel_J0(b); } int main(int argc, char *argv[]) { test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); gsl_anneal<int,multi_funct<int> > ga; double result; ovector init(2); multi_funct_fptr_noerr<int> fx(function); ga.ntrial=1000; ga.verbose=1; ga.tolx=1.0e-7; ga.T_dec=1.1; int vpx=0; // Choose an initial point at a local minimum away from // the global minimum init[0]=9.0; init[1]=9.0; // Perform the minimization ga.mmin(2,init,result,vpx,fx); cout << "x: " << init[0] << " " << init[1] << ", minimum function value: " << result << endl; cout << endl; // Test that it found the global minimum t.test_rel(init[0],2.0,1.0e-2,"another test - value"); t.test_rel(init[1],-3.0,1.0e-2,"another test - value 2"); t.test_rel(result,-1.0,1.0e-2,"another test - min"); t.report(); return 0; } // End of example
/* Example: ex_minte.cpp ------------------------------------------------------------------- An example to demonstrate multidimensional integration */ #include <o2scl/test_mgr.h> #include <o2scl/multi_funct.h> #include <o2scl/composite_inte.h> #include <o2scl/gsl_inte_qng.h> #include <o2scl/gsl_vegas.h> /// For M_PI #include <gsl/gsl_math.h> using namespace std; using namespace o2scl; double test_fun(size_t nv, const ovector_base &x, void *&vp) { double y=1.0/(1.0-cos(x[0])*cos(x[1])*cos(x[2]))/M_PI/M_PI/M_PI; return y; } int main(void) { test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); double exact = 1.3932039296; double res; double err; void *vpx=0; gsl_vegas<void *,multi_funct<void *> > gm; ovector a(3), b(3); a.set_all(0.0); b.set_all(M_PI); multi_funct_fptr_noerr<void *> tf(test_fun); gm.n_points=100000; gm.minteg_err(tf,3,a,b,vpx,res,err); cout << res << " " << exact << " " << (res-exact)/err << endl; t.test_rel(res,exact,err*10.0,"O2scl"); t.report(); return 0; } // End of example
/* Example: ex_contour.cpp ------------------------------------------------------------------- Example for generating contour lines */ #include <iostream> #include <o2scl/contour.h> #include <o2scl/ovector_tlate.h> using namespace std; using namespace o2scl; // A function defining the three-dimensional surface // for which we want to compute contour levels double fun(double x, double y) { return 15.0*exp(-pow(x-20.0,2.0)/400.0-pow(y-5.0,2.0)/25.0) +40.0*exp(-pow(x-70.0,2.0)/500.0-pow(y-2.0,2.0)/4.0); } // A function for outputting the data to cout int print_data(int nx, int ny, ovector_base &x, ovector_base &y, omatrix_base &data); // A function for printing the contour information to a file int file_out(vector<contour_line> &conts, vector<contour_line> &conts2); int main(void) { test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); contour co; // Initialize the data ovector x(12), y(10); omatrix data(10,12); for(size_t i=0;i<10;i++) { y[i]=((double)i); } for(size_t i=0;i<12;i++) { x[i]=((double)i)*((double)i); } for(size_t j=0;j<12;j++) { for(size_t k=0;k<10;k++) { data[k][j]=fun(x[j],y[k]); } } co.set_data(12,10,x,y,data); // Print out the data print_data(12,10,x,y,data); // Set the contour levels ovector levels(7); levels[0]=5.0; levels[1]=10.0; levels[2]=15.0; levels[3]=20.0; levels[4]=25.0; levels[5]=30.0; levels[6]=35.0; co.set_levels(7,levels); // Compute the contours vector<contour_line> conts; co.calc_contours(conts); // Print the contours to the screen and test to make sure // that they match the requested level size_t nc=conts.size(); for(size_t i=0;i<nc;i++) { cout << "Contour " << i << " at level " << conts[i].level << ":" << endl; size_t cs=conts[i].x.size(); for(size_t j=0;j<cs;j++) { cout << "(" << conts[i].x[j] << ", " << conts[i].y[j] << ")" << endl; //t.test_rel(fun(conts[i].x[j],conts[i].y[j]),conts[i].level, //1.5e-1,"curve"); } cout << endl; } // Refine the data using cubic spline interpolation def_interp_mgr<ovector_const_view,cspline_interp> dim1; def_interp_mgr<ovector_const_subvector,cspline_interp> dim2; co.regrid_data(5,5,dim1,dim2); // Recompute the contours vector<contour_line> conts2; co.calc_contours(conts2); // Output the contour information to a file for the documentation file_out(conts,conts2); t.report(); return 0; } // End of example
/* Example: ex_twod_intp.cpp ------------------------------------------------------------------- A simple example for two-dimensional interpolation using the twod_intp class. */ #include <o2scl/twod_intp.h> #include <o2scl/test_mgr.h> using namespace std; using namespace o2scl; // A function for filling the data and comparing results double f(double x, double y) { return pow(sin(0.1*x+0.3*y),2.0); } int main(void) { int i,j; test_mgr t; t.set_output_level(1); // Create the sample data ovector x(3), y(3); omatrix data(3,3); cout.setf(ios::scientific); // Set the grid x[0]=0.0; x[1]=1.0; x[2]=2.0; y[0]=3.0; y[1]=2.0; y[2]=1.0; // Set and print out the data cout << endl; cout << "Data: " << endl; cout << " x | "; for(i=0;i<3;i++) cout << x[i] << " "; cout << endl; cout << " y |" << endl; cout << "-------------|-"; for(i=0;i<3;i++) cout << "-------------"; cout << endl; for(i=0;i<3;i++) { cout << y[i] << " | "; for(j=0;j<3;j++) { data[i][j]=f(x[j],y[i]); cout << data[i][j] << " "; } cout << endl; } cout << endl; // Perform the interpolation cout << "x y Calc. Exact" << endl; twod_intp ti; // Interpolation, x-first double tol=0.05; double tol2=0.4; ti.set_data(3,3,x,y,data,true); double x0, y0, x1, y1; x0=0.5; y0=1.5; cout << x0 << " " << y0 << " " << ti.interp(x0,y0) << " " << f(x0,y0) << endl; x0=0.99; y0=1.99; cout << x0 << " " << y0 << " " << ti.interp(x0,y0) << " " << f(x0,y0) << endl; x0=1.0; y0=2.0; cout << x0 << " " << y0 << " " << ti.interp(x0,y0) << " " << f(x0,y0) << endl; cout << endl; // Interpolation, y-first ti.set_data(3,3,x,y,data,false); x0=0.5; y0=1.5; cout << x0 << " " << y0 << " " << ti.interp(x0,y0) << " " << f(x0,y0) << endl; x0=0.99; y0=1.99; cout << x0 << " " << y0 << " " << ti.interp(x0,y0) << " " << f(x0,y0) << endl; x0=1.0; y0=2.0; cout << x0 << " " << y0 << " " << ti.interp(x0,y0) << " " << f(x0,y0) << endl; cout << endl; t.report(); return 0; } // End of example
This example creates a sample 3 by 3 grid of data with the function and performs some interpolations and compares them with the exact result.
Data: x | 0.000000e+00 1.000000e+00 2.000000e+00 y | -------------|---------------------------------------- 3.000000e+00 | 6.136010e-01 7.080734e-01 7.942506e-01 2.000000e+00 | 3.188211e-01 4.150164e-01 5.145998e-01 1.000000e+00 | 8.733219e-02 1.516466e-01 2.298488e-01 x y Calc. Exact 5.000000e-01 1.500000e+00 2.380255e-01 2.298488e-01 9.900000e-01 1.990000e+00 4.112589e-01 4.110774e-01 1.000000e+00 2.000000e+00 4.150164e-01 4.150164e-01 5.000000e-01 1.500000e+00 2.380255e-01 2.298488e-01 9.900000e-01 1.990000e+00 4.112589e-01 4.110774e-01 1.000000e+00 2.000000e+00 4.150164e-01 4.150164e-01
/* Example: ex_mandel.cpp ------------------------------------------------------------------- Mandelbrot example demonstrating table3d and complex arithmetic */ #include <iostream> #include <o2scl/cx_arith.h> #include <o2scl/table3d.h> #include <o2scl/base_ioc.h> #include <o2scl/user_io.h> using namespace std; using namespace o2scl; int main(void) { test_mgr tm; tm.set_output_level(2); // Create a table3d object table3d t; // Add parameters double delta=0.001, minx=-1.5, maxx=0.8, miny=-1.0, maxy=1.0; size_t maxtime=0, limit=100; t.add_constant("delta",delta); t.add_constant("minx",minx); t.add_constant("maxx",maxx); t.add_constant("miny",miny); t.add_constant("maxy",maxy); // Set grid ovector ox, oy; for(double x=minx;x<=maxx;x+=delta) ox.push_back(x); for(double y=miny;y<=maxy;y+=delta) oy.push_back(y); t.set_xy("x",ox.size(),ox,"y",oy.size(),oy); // Create slice t.new_slice("time"); // Compute escape times for(size_t i=0;i<ox.size();i++) { for(size_t j=0;j<oy.size();j++) { gsl_complex c={{ox[i],oy[j]}}; gsl_complex z={{0,0}}; size_t time=0; for(size_t k=0;k<limit;k++) { // Arithmetic with gsl_complex objects z=z*z+c; if (abs(z)>10.0) { time=k; k=limit; } } t.set(i,j,"time",time); if (time>maxtime) maxtime=time; } } // Maximum escape time for color normalization t.add_constant("maxtime",maxtime); // Output to file base_ioc bio; table3d_io_type t3d; o2scl_output_text("ex_mandel.out",&t,"mandel"); tm.test_gen(maxtime==99,"maxtime test"); tm.report(); return 0; } // End of example
The information stored in the table3d object in ex_mandel.out can be plotted:
mandel_plot.png
given the boundary conditions
/* Example: ex_ode_it.cpp ------------------------------------------------------------------- Demonstrate the iterative method for solving ODEs */ #include <o2scl/ode_it_solve.h> #include <o2scl/ode_iv_solve.h> #include <o2scl/linear_solver.h> using namespace std; using namespace o2scl; using namespace o2scl_linalg; // The three-dimensional ODE system class ode_system { public: // The LHS boundary conditions double left(size_t ieq, double x, ovector_base &yleft, int &pa) { if (ieq==0) return yleft[0]-1.0; return yleft[1]*yleft[1]+yleft[2]*yleft[2]-2.0; } // The RHS boundary conditions double right(size_t ieq, double x, ovector_base &yright, int &pa) { return yright[1]-3.0; } // The differential equations double derivs(size_t ieq, double x, ovector_base &y, int &pa) { if (ieq==1) return y[0]+y[1]; else if (ieq==2) return y[0]+y[2]; return y[1]; } // This is the alternative specification for ode_iv_solve for // comparison int shoot_derivs(double x, size_t nv, const ovector_base &y, ovector_base &dydx, int &pa) { dydx[0]=y[1]; dydx[1]=y[0]+y[1]; dydx[2]=y[0]+y[2]; return 0; } }; int main(void) { test_mgr t; t.set_output_level(1); cout.setf(ios::scientific); // The ODE solver ode_it_solve<int,ode_it_funct<int,ovector_base>,ovector_base, omatrix_base,omatrix_row,ovector_base,omatrix_base> oit; // The class which contains the functions to solve ode_system os; // Make function objects for the derivatives and boundary conditions ode_it_funct_mfptr<ode_system,int> f_d(&os,&ode_system::derivs); ode_it_funct_mfptr<ode_system,int> f_l(&os,&ode_system::left); ode_it_funct_mfptr<ode_system,int> f_r(&os,&ode_system::right); // Grid size size_t ngrid=40; // Number of ODEs size_t neq=3; // Number of LHS boundary conditions size_t nbleft=2; // Create space for the solution and make an initial guess ovector x(ngrid); omatrix y(ngrid,neq); for(size_t i=0;i<ngrid;i++) { x[i]=((double)i)/((double)(ngrid-1)); y[i][0]=1.0+x[i]+1.0; y[i][1]=3.0*x[i]; y[i][2]=-0.1*x[i]-1.4; } int pa=0; // Workspace objects omatrix A(ngrid*neq,ngrid*neq); ovector rhs(ngrid*neq), dy(ngrid*neq); // Perform the solution oit.verbose=1; oit.solve(ngrid,neq,nbleft,x,y,f_d,f_l,f_r,A,rhs,dy,pa); // Compare with the initial value solver ode_iv_solve ode_iv_solve<int> ois; ode_funct_mfptr<ode_system,int> f_sd(&os,&ode_system::shoot_derivs); ovector ystart(neq), yend(neq); for(size_t i=0;i<neq;i++) ystart[i]=y[0][i]; ois.solve_final_value(0.0,1.0,0.01,neq,ystart,yend,pa,f_sd); // Test the result t.test_rel(y[0][0],1.0,1.0e-3,"ya"); t.test_rel(y[ngrid-1][0],yend[0],1.0e-3,"yb"); t.test_rel(y[0][1],0.25951,1.0e-3,"yc"); t.test_rel(y[ngrid-1][1],yend[1],1.0e-3,"yd"); t.test_rel(y[0][2],-1.3902,1.0e-3,"ye"); t.test_rel(y[ngrid-1][2],yend[2],1.0e-3,"yf"); t.report(); return 0; } // End of example
Header file dependencies
For reference, it's useful to know how the top-level header files depend on each other, since it can be difficult to trace everything down. In the base
directory, the following are some of the most "top-level" header files and their associated dependencies within O2scl (there are other dependencies on GSL and the C standard library not listed here).
err_hnd.h : (none) lib_settings.h : (none) array.h: err_hnd.h vector.h: err_hnd.h sring_conv.h : lib_settings.h misc.h : err_hnd.h lib_settings.h test_mgr.h : string_conv.h uvector_tlate.h: err_hnd.h string_conv.h array.h vector.h ovector_tlate.h: err_hnd.h string_conv.h uvector_tlate.h array.h vector.h
The use of templates
Templates are used extensively, and this makes for longer compilation times so any code that can be removed conveniently from the header files should be put into source code files instead.
Two approaches to thread-safe error handling which are worth comparing: the first is GSL which uses return codes and global function for an error handler, and the second is the Math/Special Functions section of Boost, which uses a separate policy type for each function. One issue is thread safety: the GSL approach is thread safe only in the sense that one can in principle use the return codes in different threads to track errors. What one cannot do in GSL is use different user-defined error handlers for different threads. The Special Functions library allows one to choose a different Policy for every special function call, and thus allows quite a bit more flexibility in designing multi-threaded error handling.
However, ensuring const-correctness makes the design a bit thorny, and this is still in progress.
In GSL, the preprocessor output for vector/view_source.c
is:
gsl_vector_const_view_array (const double * base, size_t n) { _gsl_vector_const_view view = {{0, 0, 0, 0, 0}}; if (n == 0) { do { gsl_error ("vector length n must be positive integer", "view_source.c", 28, GSL_EINVAL) ; return view ; } while (0); } { gsl_vector v = {0, 0, 0, 0, 0}; v.data = (double *)base ; v.size = n; v.stride = 1; v.block = 0; v.owner = 0; ((_gsl_vector_view *)&view)->vector = v; return view; } }
src/base/ovector_tlate.h
.O2SCL_
.
Range-checking for arrays and matrices is turned on by default, but can be turned off by defining O2SCL_NO_RANGE_CHECK
during the initial configuration of the library. To see how the library was configured at runtime, use the lib_settings class.
There are several macros for error handling defined in err_hnd.h, and several for vector/matrix arithmetic in vec_arith.h .
There is a define constant O2SCL_NO_SYSTEM_FUNC which permanently disables the shell command '!'
in cli (when the constant is defined, the shell command doesn't work even if cli::shell_cmd_allowed is true
).
The constant O2SCL_DATA_DIR is defined internally to provide the directory which contains the O2scl data files. After installation, this can be accessed in lib_settings.
All of the header files have their own define constant of the form O2SCL_HEADER_FILE_NAME
which ensures that the header file is only included once.
Finally, I sometimes comment out sections of code with
#ifdef O2SCL_NEVER_DEFINED
...
#endif
All other global objects are to be avoided.
Other Improvements:
I'm particularly interested in improving the ODE and fitting classes, as well as updating the BFGS2 minimizer. Of course, more examples and better documentation are also a must.
Algorithms to include
Complex numbers
I'm not sure where to go with complex numbers. My guess is that std::complex
is not significantly slower (or is faster) than gsl_complex
, but it would be good to check this. Then there's the C99 standard, which is altogether different. Unfortunately the interfaces may be sufficiently different that it's impossible to make templated classes which operate on generic complex number types.
I/O
The I/O classes are (admittedly) not structured very well, and there are a lot of things which could be done there. There are a lot of alternative solutions out there, but most of them work on binary file formats (which I find difficult to use).
boost::any
, which will avoid the silly void *
s all over the place. This is already in progress.
COPYING
and in doc/o2scl/extras/gpl_license.txt
. After installation, it is included in the documentation in PREFIX/doc/extras/gpl_license.txt
where the default PREFIX
is /usr/local
.
GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: <program> Copyright (C) <year> <name of author> This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <http://www.gnu.org/licenses/>. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <http://www.gnu.org/philosophy/why-not-lgpl.html>.
This documentation is provided under the GNU Free Documentation License, as given below and provided in doc/o2scl/extras/fdl_license.txt
. After installation, it is included in the documentation in PREFIX/doc/extras/fdl_license.txt
where the default PREFIX
is /usr/local
.
GNU Free Documentation License Version 1.2, November 2002 Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. 0. PREAMBLE The purpose of this License is to make a manual, textbook, or other functional and useful document "free" in the sense of freedom: to assure everyone the effective freedom to copy and redistribute it, with or without modifying it, either commercially or noncommercially. Secondarily, this License preserves for the author and publisher a way to get credit for their work, while not being considered responsible for modifications made by others. This License is a kind of "copyleft", which means that derivative works of the document must themselves be free in the same sense. It complements the GNU General Public License, which is a copyleft license designed for free software. We have designed this License in order to use it for manuals for free software, because free software needs free documentation: a free program should come with manuals providing the same freedoms that the software does. But this License is not limited to software manuals; it can be used for any textual work, regardless of subject matter or whether it is published as a printed book. We recommend this License principally for works whose purpose is instruction or reference. 1. APPLICABILITY AND DEFINITIONS This License applies to any manual or other work, in any medium, that contains a notice placed by the copyright holder saying it can be distributed under the terms of this License. Such a notice grants a world-wide, royalty-free license, unlimited in duration, to use that work under the conditions stated herein. The "Document", below, refers to any such manual or work. Any member of the public is a licensee, and is addressed as "you". You accept the license if you copy, modify or distribute the work in a way requiring permission under copyright law. A "Modified Version" of the Document means any work containing the Document or a portion of it, either copied verbatim, or with modifications and/or translated into another language. A "Secondary Section" is a named appendix or a front-matter section of the Document that deals exclusively with the relationship of the publishers or authors of the Document to the Document's overall subject (or to related matters) and contains nothing that could fall directly within that overall subject. (Thus, if the Document is in part a textbook of mathematics, a Secondary Section may not explain any mathematics.) The relationship could be a matter of historical connection with the subject or with related matters, or of legal, commercial, philosophical, ethical or political position regarding them. The "Invariant Sections" are certain Secondary Sections whose titles are designated, as being those of Invariant Sections, in the notice that says that the Document is released under this License. If a section does not fit the above definition of Secondary then it is not allowed to be designated as Invariant. The Document may contain zero Invariant Sections. If the Document does not identify any Invariant Sections then there are none. The "Cover Texts" are certain short passages of text that are listed, as Front-Cover Texts or Back-Cover Texts, in the notice that says that the Document is released under this License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text may be at most 25 words. A "Transparent" copy of the Document means a machine-readable copy, represented in a format whose specification is available to the general public, that is suitable for revising the document straightforwardly with generic text editors or (for images composed of pixels) generic paint programs or (for drawings) some widely available drawing editor, and that is suitable for input to text formatters or for automatic translation to a variety of formats suitable for input to text formatters. A copy made in an otherwise Transparent file format whose markup, or absence of markup, has been arranged to thwart or discourage subsequent modification by readers is not Transparent. An image format is not Transparent if used for any substantial amount of text. A copy that is not "Transparent" is called "Opaque". Examples of suitable formats for Transparent copies include plain ASCII without markup, Texinfo input format, LaTeX input format, SGML or XML using a publicly available DTD, and standard-conforming simple HTML, PostScript or PDF designed for human modification. Examples of transparent image formats include PNG, XCF and JPG. Opaque formats include proprietary formats that can be read and edited only by proprietary word processors, SGML or XML for which the DTD and/or processing tools are not generally available, and the machine-generated HTML, PostScript or PDF produced by some word processors for output purposes only. The "Title Page" means, for a printed book, the title page itself, plus such following pages as are needed to hold, legibly, the material this License requires to appear in the title page. For works in formats which do not have any title page as such, "Title Page" means the text near the most prominent appearance of the work's title, preceding the beginning of the body of the text. A section "Entitled XYZ" means a named subunit of the Document whose title either is precisely XYZ or contains XYZ in parentheses following text that translates XYZ in another language. (Here XYZ stands for a specific section name mentioned below, such as "Acknowledgements", "Dedications", "Endorsements", or "History".) To "Preserve the Title" of such a section when you modify the Document means that it remains a section "Entitled XYZ" according to this definition. The Document may include Warranty Disclaimers next to the notice which states that this License applies to the Document. These Warranty Disclaimers are considered to be included by reference in this License, but only as regards disclaiming warranties: any other implication that these Warranty Disclaimers may have is void and has no effect on the meaning of this License. 2. VERBATIM COPYING You may copy and distribute the Document in any medium, either commercially or noncommercially, provided that this License, the copyright notices, and the license notice saying this License applies to the Document are reproduced in all copies, and that you add no other conditions whatsoever to those of this License. You may not use technical measures to obstruct or control the reading or further copying of the copies you make or distribute. However, you may accept compensation in exchange for copies. If you distribute a large enough number of copies you must also follow the conditions in section 3. You may also lend copies, under the same conditions stated above, and you may publicly display copies. 3. COPYING IN QUANTITY If you publish printed copies (or copies in media that commonly have printed covers) of the Document, numbering more than 100, and the Document's license notice requires Cover Texts, you must enclose the copies in covers that carry, clearly and legibly, all these Cover Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on the back cover. Both covers must also clearly and legibly identify you as the publisher of these copies. The front cover must present the full title with all words of the title equally prominent and visible. You may add other material on the covers in addition. Copying with changes limited to the covers, as long as they preserve the title of the Document and satisfy these conditions, can be treated as verbatim copying in other respects. If the required texts for either cover are too voluminous to fit legibly, you should put the first ones listed (as many as fit reasonably) on the actual cover, and continue the rest onto adjacent pages. If you publish or distribute Opaque copies of the Document numbering more than 100, you must either include a machine-readable Transparent copy along with each Opaque copy, or state in or with each Opaque copy a computer-network location from which the general network-using public has access to download using public-standard network protocols a complete Transparent copy of the Document, free of added material. If you use the latter option, you must take reasonably prudent steps, when you begin distribution of Opaque copies in quantity, to ensure that this Transparent copy will remain thus accessible at the stated location until at least one year after the last time you distribute an Opaque copy (directly or through your agents or retailers) of that edition to the public. It is requested, but not required, that you contact the authors of the Document well before redistributing any large number of copies, to give them a chance to provide you with an updated version of the Document. 4. MODIFICATIONS You may copy and distribute a Modified Version of the Document under the conditions of sections 2 and 3 above, provided that you release the Modified Version under precisely this License, with the Modified Version filling the role of the Document, thus licensing distribution and modification of the Modified Version to whoever possesses a copy of it. In addition, you must do these things in the Modified Version: A. Use in the Title Page (and on the covers, if any) a title distinct from that of the Document, and from those of previous versions (which should, if there were any, be listed in the History section of the Document). You may use the same title as a previous version if the original publisher of that version gives permission. B. List on the Title Page, as authors, one or more persons or entities responsible for authorship of the modifications in the Modified Version, together with at least five of the principal authors of the Document (all of its principal authors, if it has fewer than five), unless they release you from this requirement. C. State on the Title page the name of the publisher of the Modified Version, as the publisher. D. Preserve all the copyright notices of the Document. E. Add an appropriate copyright notice for your modifications adjacent to the other copyright notices. F. Include, immediately after the copyright notices, a license notice giving the public permission to use the Modified Version under the terms of this License, in the form shown in the Addendum below. G. Preserve in that license notice the full lists of Invariant Sections and required Cover Texts given in the Document's license notice. H. Include an unaltered copy of this License. I. Preserve the section Entitled "History", Preserve its Title, and add to it an item stating at least the title, year, new authors, and publisher of the Modified Version as given on the Title Page. If there is no section Entitled "History" in the Document, create one stating the title, year, authors, and publisher of the Document as given on its Title Page, then add an item describing the Modified Version as stated in the previous sentence. J. Preserve the network location, if any, given in the Document for public access to a Transparent copy of the Document, and likewise the network locations given in the Document for previous versions it was based on. These may be placed in the "History" section. You may omit a network location for a work that was published at least four years before the Document itself, or if the original publisher of the version it refers to gives permission. K. For any section Entitled "Acknowledgements" or "Dedications", Preserve the Title of the section, and preserve in the section all the substance and tone of each of the contributor acknowledgements and/or dedications given therein. L. Preserve all the Invariant Sections of the Document, unaltered in their text and in their titles. Section numbers or the equivalent are not considered part of the section titles. M. Delete any section Entitled "Endorsements". Such a section may not be included in the Modified Version. N. Do not retitle any existing section to be Entitled "Endorsements" or to conflict in title with any Invariant Section. O. Preserve any Warranty Disclaimers. If the Modified Version includes new front-matter sections or appendices that qualify as Secondary Sections and contain no material copied from the Document, you may at your option designate some or all of these sections as invariant. To do this, add their titles to the list of Invariant Sections in the Modified Version's license notice. These titles must be distinct from any other section titles. You may add a section Entitled "Endorsements", provided it contains nothing but endorsements of your Modified Version by various parties--for example, statements of peer review or that the text has been approved by an organization as the authoritative definition of a standard. You may add a passage of up to five words as a Front-Cover Text, and a passage of up to 25 words as a Back-Cover Text, to the end of the list of Cover Texts in the Modified Version. Only one passage of Front-Cover Text and one of Back-Cover Text may be added by (or through arrangements made by) any one entity. If the Document already includes a cover text for the same cover, previously added by you or by arrangement made by the same entity you are acting on behalf of, you may not add another; but you may replace the old one, on explicit permission from the previous publisher that added the old one. The author(s) and publisher(s) of the Document do not by this License give permission to use their names for publicity for or to assert or imply endorsement of any Modified Version. 5. COMBINING DOCUMENTS You may combine the Document with other documents released under this License, under the terms defined in section 4 above for modified versions, provided that you include in the combination all of the Invariant Sections of all of the original documents, unmodified, and list them all as Invariant Sections of your combined work in its license notice, and that you preserve all their Warranty Disclaimers. The combined work need only contain one copy of this License, and multiple identical Invariant Sections may be replaced with a single copy. If there are multiple Invariant Sections with the same name but different contents, make the title of each such section unique by adding at the end of it, in parentheses, the name of the original author or publisher of that section if known, or else a unique number. Make the same adjustment to the section titles in the list of Invariant Sections in the license notice of the combined work. In the combination, you must combine any sections Entitled "History" in the various original documents, forming one section Entitled "History"; likewise combine any sections Entitled "Acknowledgements", and any sections Entitled "Dedications". You must delete all sections Entitled "Endorsements". 6. COLLECTIONS OF DOCUMENTS You may make a collection consisting of the Document and other documents released under this License, and replace the individual copies of this License in the various documents with a single copy that is included in the collection, provided that you follow the rules of this License for verbatim copying of each of the documents in all other respects. You may extract a single document from such a collection, and distribute it individually under this License, provided you insert a copy of this License into the extracted document, and follow this License in all other respects regarding verbatim copying of that document. 7. AGGREGATION WITH INDEPENDENT WORKS A compilation of the Document or its derivatives with other separate and independent documents or works, in or on a volume of a storage or distribution medium, is called an "aggregate" if the copyright resulting from the compilation is not used to limit the legal rights of the compilation's users beyond what the individual works permit. When the Document is included in an aggregate, this License does not apply to the other works in the aggregate which are not themselves derivative works of the Document. If the Cover Text requirement of section 3 is applicable to these copies of the Document, then if the Document is less than one half of the entire aggregate, the Document's Cover Texts may be placed on covers that bracket the Document within the aggregate, or the electronic equivalent of covers if the Document is in electronic form. Otherwise they must appear on printed covers that bracket the whole aggregate. 8. TRANSLATION Translation is considered a kind of modification, so you may distribute translations of the Document under the terms of section 4. Replacing Invariant Sections with translations requires special permission from their copyright holders, but you may include translations of some or all Invariant Sections in addition to the original versions of these Invariant Sections. You may include a translation of this License, and all the license notices in the Document, and any Warranty Disclaimers, provided that you also include the original English version of this License and the original versions of those notices and disclaimers. In case of a disagreement between the translation and the original version of this License or a notice or disclaimer, the original version will prevail. If a section in the Document is Entitled "Acknowledgements", "Dedications", or "History", the requirement (section 4) to Preserve its Title (section 1) will typically require changing the actual title. 9. TERMINATION You may not copy, modify, sublicense, or distribute the Document except as expressly provided for under this License. Any other attempt to copy, modify, sublicense or distribute the Document is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 10. FUTURE REVISIONS OF THIS LICENSE The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See http://www.gnu.org/copyleft/. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this License "or any later version" applies to it, you have the option of following the terms and conditions either of that specified version or of any later version that has been published (not as a draft) by the Free Software Foundation. If the Document does not specify a version number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and license notices just after the title page: Copyright (c) YEAR YOUR NAME. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the "with...Texts." line with this: with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. If you have Invariant Sections without Cover Texts, or some other combination of the three, merge those two alternatives to suit the situation. If your document contains nontrivial examples of program code, we recommend releasing these examples in parallel under your choice of free software license, such as the GNU General Public License, to permit their use in free software.
ex_hydrogen
example.
Bader83: G. Bader and P. Deuflhard, Numer. Math. 41 (1983) 373.
Bus75: J. C. P. Bus and T. J. Dekker, ACM Trans. Math. Soft. 1 (1975) 330.
Cash90: J. R. Cash and A. H. Karp, ACM Trans. Math. Soft. 16 (1990) 201.
EngelnMullges96: G. Engeln-Mullges and F. Uhlig, Numerical Algorithms in C (1996) Springer, p. 96.
Fletcher87: R. Fletcher, Practical methods of optimization (John Wiley & Sons, Chichester 1987) p. 39.
Garbow80: B. S. Garbow, K. E. Hillstrom, and J. J. More, MINPACK project, Argonne Nat'l Lab, March 1980.
Hairer00: Hairer, E., Norsett S.P., Wanner, G. Solving ordinary differential equations I, Nonstiff Problems, 2nd revised edition, Springer, 2000.
Krabs83: W. Krabs, Einfuhrung in die lieare und nictlineare Optimierung fur Ingenieure (BSB B.G. Teubner, Leipzig 1983) p. 84.
Lepage78: G. P. Lepage, J. Comp. Phys. 27 (1978) 192.
Lewin83: L. Lewin, Polylogarithms and Associated Functions (North-Holland, New York, 1983).
Longman58: I.M. Longman, MTAC (later renamed Math. Comp.) 12 (1958) 205.
More79: J.J. More' and M.Y. Cosnard, ACM Trans. Math. Software, 5 (1979) 64-85.
More80: J.J. More' and M.Y. Cosnard, Algoright 554 BRENTM, Collected Algorithms from CACM (1980).
Nelder65: Nelder, J.A., Mead, R., Computer Journal 7 (1965) pp. 308-313.
Press90: W.H. Press, G.R. Farrar, "Recursive Stratified Sampling for Multidimensional Monte Carlo Integration", Computers in Physics, v4 (1990), pp. 190-195.
Prince81: P.J. Prince and J.R. Dormand J. Comp. Appl. Math., 7 (1981) 67.
Rutishauser63: H. Rutishauser, Ausdehnung des Rombergschen Prinzips (Extension of Romberg's Principle), Numer. Math. 5 (1963) 48-54.
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page