CoolProp  4.2.5
An open-source fluid property and humid air property database
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Functions
Solvers.h File Reference
#include <vector>
#include <string>
#include "CPExceptions.h"

Go to the source code of this file.

Classes

class  FuncWrapper1D
 
class  FuncWrapperND
 

Functions

double Brent (FuncWrapper1D *f, double a, double b, double macheps, double t, int maxiter, std::string *errstr)
 
double Secant (FuncWrapper1D *f, double x0, double dx, double ftol, int maxiter, std::string *errstring)
 
double BoundedSecant (FuncWrapper1D *f, double x0, double xmin, double xmax, double dx, double ftol, int maxiter, std::string *errstring)
 
double Newton (FuncWrapper1D *f, double x0, double ftol, int maxiter, std::string *errstring)
 
std::vector< double > NDNewtonRaphson_Jacobian (FuncWrapperND *f, std::vector< double > x0, double tol, int maxiter, std::string *errstring)
 

Function Documentation

double BoundedSecant ( FuncWrapper1D f,
double  x0,
double  xmin,
double  xmax,
double  dx,
double  tol,
int  maxiter,
std::string *  errstring 
)

In the secant function, a 1-D Newton-Raphson solver is implemented. An initial guess for the solution is provided.

Parameters
fA pointer to an instance of the FuncWrapper1D class that implements the call() function
x0The inital guess for the solution
xmaxThe upper bound for the solution
xminThe lower bound for the solution
dxThe initial amount that is added to x in order to build the numerical derivative
tolThe absolute value of the tolerance accepted for the objective function
maxiterMaximum number of iterations
errstringA pointer to the std::string that returns the error from Secant. Length is zero if no errors are found
Returns
If no errors are found, the solution, otherwise the value _HUGE, the value for infinity

Definition at line 179 of file Solvers.cpp.

double Brent ( FuncWrapper1D f,
double  a,
double  b,
double  macheps,
double  t,
int  maxiter,
std::string *  errstr 
)

This function implements a 1-D bounded solver using the algorithm from Brent, R. P., Algorithms for Minimization Without Derivatives. Englewood Cliffs, NJ: Prentice-Hall, 1973. Ch. 3-4.

a and b must bound the solution of interest and f(a) and f(b) must have opposite signs. If the function is continuous, there must be at least one solution in the interval [a,b].

Parameters
fA pointer to an instance of the FuncWrapper1D class that must implement the class() function
aThe minimum bound for the solution of f=0
bThe maximum bound for the solution of f=0
machepsThe machine precision
tTolerance (absolute)
maxiterMaximum numer of steps allowed. Will throw a SolutionError if the solution cannot be found
errstrA pointer to the error string returned. If length is zero, no errors found.

Definition at line 235 of file Solvers.cpp.

std::vector<double> NDNewtonRaphson_Jacobian ( FuncWrapperND f,
std::vector< double >  x0,
double  tol,
int  maxiter,
std::string *  errstring 
)

In this formulation of the Multi-Dimensional Newton-Raphson solver the Jacobian matrix is known. Therefore, the dx vector can be obtained from

J(x)dx=-f(x)

for a given value of x. The pointer to the class FuncWrapperND that is passed in must implement the call() and Jacobian() functions, each of which take the vector x. The data is managed using std::vector<double> vectors

Parameters
fA pointer to an subclass of the FuncWrapperND class that implements the call() and Jacobian() functions
x0The initial guess value for the solution
tolThe root-sum-square of the errors from each of the components
maxiterThe maximum number of iterations
errstringA string with the returned error. If the length of errstring is zero, no errors were found
Returns
If no errors are found, the solution. Otherwise, _HUGE, the value for infinity

Definition at line 47 of file Solvers.cpp.

double Newton ( FuncWrapper1D f,
double  x0,
double  ftol,
int  maxiter,
std::string *  errstring 
)

In the newton function, a 1-D Newton-Raphson solver is implemented using exact solutions. An initial guess for the solution is provided.

Parameters
fA pointer to an instance of the FuncWrapper1D class that implements the call() function
x0The inital guess for the solution
ftolThe absolute value of the tolerance accepted for the objective function
maxiterMaximum number of iterations
errstringA pointer to the std::string that returns the error from Secant. Length is zero if no errors are found
Returns
If no errors are found, the solution, otherwise the value _HUGE, the value for infinity

Definition at line 85 of file Solvers.cpp.

double Secant ( FuncWrapper1D f,
double  x0,
double  dx,
double  tol,
int  maxiter,
std::string *  errstring 
)

In the secant function, a 1-D Newton-Raphson solver is implemented. An initial guess for the solution is provided.

Parameters
fA pointer to an instance of the FuncWrapper1D class that implements the call() function
x0The inital guess for the solutionh
dxThe initial amount that is added to x in order to build the numerical derivative
tolThe absolute value of the tolerance accepted for the objective function
maxiterMaximum number of iterations
errstringA pointer to the std::string that returns the error from Secant. Length is zero if no errors are found
Returns
If no errors are found, the solution, otherwise the value _HUGE, the value for infinity

Definition at line 123 of file Solvers.cpp.