CoolProp
4.2.5
An open-source fluid property and humid air property database
|
#include <vector>
#include "Solvers.h"
#include "math.h"
#include "MatrixMath.h"
#include <iostream>
#include "CoolPropTools.h"
Go to the source code of this file.
Functions | |
std::vector< double > | NDNewtonRaphson_Jacobian (FuncWrapperND *f, std::vector< double > x0, double tol, int maxiter, std::string *errstring) |
double | Newton (FuncWrapper1D *f, double x0, double ftol, int maxiter, std::string *errstring) |
double | Secant (FuncWrapper1D *f, double x0, double dx, double tol, int maxiter, std::string *errstring) |
double | BoundedSecant (FuncWrapper1D *f, double x0, double xmin, double xmax, double dx, double tol, int maxiter, std::string *errstring) |
double | Brent (FuncWrapper1D *f, double a, double b, double macheps, double t, int maxiter, std::string *errstr) |
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.
f | A pointer to an instance of the FuncWrapper1D class that implements the call() function |
x0 | The inital guess for the solution |
xmax | The upper bound for the solution |
xmin | The lower bound for the solution |
dx | The initial amount that is added to x in order to build the numerical derivative |
tol | The absolute value of the tolerance accepted for the objective function |
maxiter | Maximum number of iterations |
errstring | A pointer to the std::string that returns the error from Secant. Length is zero if no errors are found |
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].
f | A pointer to an instance of the FuncWrapper1D class that must implement the class() function |
a | The minimum bound for the solution of f=0 |
b | The maximum bound for the solution of f=0 |
macheps | The machine precision |
t | Tolerance (absolute) |
maxiter | Maximum numer of steps allowed. Will throw a SolutionError if the solution cannot be found |
errstr | A 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
f | A pointer to an subclass of the FuncWrapperND class that implements the call() and Jacobian() functions |
x0 | The initial guess value for the solution |
tol | The root-sum-square of the errors from each of the components |
maxiter | The maximum number of iterations |
errstring | A string with the returned error. If the length of errstring is zero, no errors were found |
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.
f | A pointer to an instance of the FuncWrapper1D class that implements the call() function |
x0 | The inital guess for the solution |
ftol | The absolute value of the tolerance accepted for the objective function |
maxiter | Maximum number of iterations |
errstring | A pointer to the std::string that returns the error from Secant. Length is zero if no errors are found |
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.
f | A pointer to an instance of the FuncWrapper1D class that implements the call() function |
x0 | The inital guess for the solutionh |
dx | The initial amount that is added to x in order to build the numerical derivative |
tol | The absolute value of the tolerance accepted for the objective function |
maxiter | Maximum number of iterations |
errstring | A pointer to the std::string that returns the error from Secant. Length is zero if no errors are found |
Definition at line 123 of file Solvers.cpp.