| 
    chemmisol 0.1
    
   | 
 
#include <newton.h>
Public Member Functions | |
| Newton (const X &x0, std::function< X(const X &)> f, std::function< M(const X &)> df) | |
| X | solve_eps (float epsilon) const | 
| X | solve_iter (std::size_t n) const | 
Implementation of the Newton-Raphson method. The algorithm is generalized to solve systems of equations of k variables and k functions.
The algorithm recursively refines the x value using the following formulae:
x_n+1 = G(x_n - df(x_n)^-1 * f(x_n))
 where f denotes the function to solve so that f(x)=0, df denotes the Jacobian matrix of f, and G is a function that takes x as parameter and returns a vector of the same size.
By default, G is the identity(), what allows to implement the classical Newton-Raphson method.
When G is set to abs(), the so-called AbsoluteNewton method is implemented.
The convergence is guaranteed only when the initial value is "close enough" to the desired solution.
| X | Vector type of size n that defines the argument type and return value of the function f.  | 
| M | Matrix type of size n*n used to represent the Jacobian matrix of f, as returned by df.  | 
| G | Function applied to current x at the end of each iteration of the algorithm. | 
      
  | 
  inline | 
Defines a Newton solver.
| x0 | Initial x value, that should be "close enough" to the solution to guarantee convergence. | 
| f | Function to solve so that f(x)=0.  | 
| df | Derivative of f, that returns the values of the Jacobian matrix of f for a specified x. | 
| X chemmisol::Newton< X, M, G >::solve_eps | ( | float | epsilon | ) | const | 
Runs the solver until f(x) < eps for n iterations and returns the found value of x such that f(x) < eps.
| epsilon | Required precision. | 
| X chemmisol::Newton< X, M, G >::solve_iter | ( | std::size_t | n | ) | const | 
Runs the solver for n iterations and returns the found value of x such that f(x)=0.