|
suanPan
🧮 An Open Source, Parallel and Heterogeneous Finite Element Analysis Framework
|
#include <suanPan.h>Go to the source code of this file.
Functions | |
| template<std::floating_point T, std::invocable< T > F> | |
| T | brent (F &&func, const T x1, const T x2, const T tol) |
| Implements Brent's method for finding a root of a function within a given interval. | |
| T brent | ( | F && | func, |
| const T | x1, | ||
| const T | x2, | ||
| const T | tol | ||
| ) |
Implements Brent's method for finding a root of a function within a given interval.
Brent's method combines the bisection method, the secant method, and inverse quadratic interpolation to efficiently find a root of a function. It is robust and guarantees convergence as long as the function changes sign over the interval [x1, x2].
| T | The floating-point type (e.g., float, double, long double). |
| F | The callable type representing the function to find the root of. Must accept a single argument of type T and return a value of type T. |
| func | The function for which the root is to be found. It must be continuous and change sign over the interval [x1, x2]. |
| x1 | The lower bound of the interval. |
| x2 | The upper bound of the interval. |
| tol | The desired tolerance for the root. The algorithm stops when the root is found to this precision. |