Class Solver managing the solving process and creating the Stepper object.
More...
#include <solver_def.hpp>
|
| | Solver (std::function< double(double)> fun, T initial_guess, const Method method, int max_iterations, double tolerance, bool aitken_mode, bool verbose) |
| | Constructor for Solver object.
|
| |
| | Solver (std::function< double(double)> fun, T initial_guess, const Method method, int max_iterations, double tolerance, bool aitken_mode, bool verbose, std::function< double(double)> derivative_or_function_g) |
| | Constructor for Solver object.
|
| |
| Eigen::MatrixX2d | solve () |
| | Calls everything required to Solve with a method.
|
| |
|
| Method | method |
| | Method which will be used - defined thanks to.
|
| |
| int | max_iterations |
| | Stores the maximum iterations for the method.
|
| |
| double | tolerance |
| | Stores the tolerance below which the process ends.
|
| |
| bool | aitken_requirement |
| | True if Aitken acceleration is required, 0 otherwise.
|
| |
| bool | verbose |
| | Verbose mode flag.
|
| |
| std::function< double(double)> | derivative_or_function_g |
| | Stores the derivative or g_function of the function if needed.
|
| |
| Eigen::MatrixX2d | results |
| |
| std::function< double(double)> | function |
| | Stores the function to find the root of and the starting guess for the process.
|
| |
| T | initial_guess |
| | Templated initial_guess for the method, whose type changes depending on the method itself.
|
| |
template<typename T>
class Solver< T >
Class Solver managing the solving process and creating the Stepper object.
◆ Solver() [1/2]
template<typename T >
| Solver< T >::Solver |
( |
std::function< double(double)> |
fun, |
|
|
T |
initial_guess, |
|
|
const Method |
method, |
|
|
int |
max_iterations, |
|
|
double |
tolerance, |
|
|
bool |
aitken_mode, |
|
|
bool |
verbose |
|
) |
| |
Constructor for Solver object.
- Parameters
-
| fun | The function to find the root of |
| initial_guess | The initial guess(es) or interval |
| method | The method which will be used for the Solution |
| max_iterations | Maximum iterations in which the method has to converge |
| tolerance | The tolerance below which the error/function will make the method converge |
| aitken_mode | Option to apply Aitken's acceleration |
| verbose | Option to give verbose output |
◆ Solver() [2/2]
template<typename T >
| Solver< T >::Solver |
( |
std::function< double(double)> |
fun, |
|
|
T |
initial_guess, |
|
|
const Method |
method, |
|
|
int |
max_iterations, |
|
|
double |
tolerance, |
|
|
bool |
aitken_mode, |
|
|
bool |
verbose, |
|
|
std::function< double(double)> |
derivative_or_function_g |
|
) |
| |
Constructor for Solver object.
- Parameters
-
| fun | The function to find the root of |
| initial_guess | The initial guess(es) or interval |
| method | The method which will be used for the Solution |
| max_iterations | Maximum iterations in which the method has to converge |
| tolerance | The tolerance below which the error/function will make the method converge |
| aitken_mode | Option to apply Aitken's acceleration |
| verbose | Option to give verbose output |
| derivative_or_function_g | The derivative of the function (for Newton) or g_function (for Fixed Point) |
◆ calculate_error()
template<typename T >
| double Solver< T >::calculate_error |
( |
double |
x_prev, |
|
|
double |
x_next |
|
) |
| |
|
private |
Computes the error of the latest iteration.
- Parameters
-
| x_next | The new guess x(i) |
| x_prev | The old guess x(i-1) |
- Returns
- |x_next - x_prev|
◆ convert_stepper() [1/3]
| void Solver< double >::convert_stepper |
( |
std::unique_ptr< StepperBase< double > > & |
stepper | ) |
|
|
private |
◆ convert_stepper() [2/3]
| void Solver< Eigen::Vector2d >::convert_stepper |
( |
std::unique_ptr< StepperBase< Eigen::Vector2d > > & |
stepper | ) |
|
|
private |
◆ convert_stepper() [3/3]
Converts the generic Abstract stepper into a typed one.
- Parameters
-
| stepper | The original abstract stepper to be converted |
◆ get_previous_result()
template<typename T >
| Eigen::Vector2d Solver< T >::get_previous_result |
( |
int |
step_length | ) |
|
|
private |
Returns a row of the results' matrix.
- Parameters
-
| step_length | tells how far to go up from the bottom row |
- Returns
- 2-dimensional vector storing x(end - step_length) and f(x(end - step_length))
◆ save_results()
template<typename T >
| void Solver< T >::save_results |
( |
int |
iter, |
|
|
Eigen::Vector2d |
result_to_save |
|
) |
| |
|
private |
Saves the result of a step in a defined row of the results' matrix.
- Parameters
-
| iter | The row index in which to store the result |
| result_to_save | 2-dimensional vector storing the new guess x(i) and the evaluation at it f(x(i)) |
◆ save_starting_point() [1/3]
| void Solver< double >::save_starting_point |
( |
| ) |
|
|
private |
◆ save_starting_point() [2/3]
| void Solver< Eigen::Vector2d >::save_starting_point |
( |
| ) |
|
|
private |
◆ save_starting_point() [3/3]
template<typename T >
| void Solver< T >::save_starting_point |
( |
| ) |
|
|
private |
Saves the actual initial guess in the top row of the results' matrix, no matter what type will be the Class argument initial_guess.
◆ solve()
template<typename T >
| Eigen::MatrixX2d Solver< T >::solve |
( |
| ) |
|
Calls everything required to Solve with a method.
- Returns
- Matrix storing in the first column x(i) for each iteration i, in the second column f(x(i))
◆ solver_step()
template<typename T >
| void Solver< T >::solver_step |
( |
int & |
iter, |
|
|
std::unique_ptr< StepperBase< T > > & |
stepper, |
|
|
double & |
err |
|
) |
| |
|
private |
Creates the stepper, calls the step computation, the error calculation and the results' saver.
- Parameters
-
| iter | Reference to the current iteration, which will be increased once the step is computed |
| stepper | The stepper object previously created and specialized depending on the method |
| err | Reference to the error, which will be computed and updated to check convergence |
◆ SolverTester
Friend class for unit testing purposes.
◆ aitken_requirement
template<typename T >
| bool Solver< T >::aitken_requirement |
|
private |
True if Aitken acceleration is required, 0 otherwise.
◆ derivative_or_function_g
template<typename T >
| std::function<double(double)> Solver< T >::derivative_or_function_g |
|
private |
Stores the derivative or g_function of the function if needed.
◆ function
template<typename T >
| std::function<double(double)> Solver< T >::function |
|
private |
Stores the function to find the root of and the starting guess for the process.
◆ initial_guess
Templated initial_guess for the method, whose type changes depending on the method itself.
◆ max_iterations
template<typename T >
| int Solver< T >::max_iterations |
|
private |
Stores the maximum iterations for the method.
◆ method
Method which will be used - defined thanks to.
- Author
- Saransh-ccp's Reader
◆ results
template<typename T >
| Eigen::MatrixX2d Solver< T >::results |
|
private |
Stores in the first column the points computed at each step, in the second the value of the function at those points.
◆ tolerance
Stores the tolerance below which the process ends.
◆ verbose
The documentation for this class was generated from the following files: