1#ifndef ROOT_STEPPER_HPP
2#define ROOT_STEPPER_HPP
13 this->aitken_requirement = aitken_mode;
18 if (!this->aitken_requirement) {
19 return this->compute_step(previous_step);
21 return this->aitken_step(previous_step);
27 Eigen::Vector2d iter_one = this->compute_step(previous_iter);
28 Eigen::Vector2d iter_two = this->compute_step(iter_one);
29 double denominator = (iter_two(0) - iter_one(0)) / (iter_one(0) - previous_iter(0));
30 if (denominator == 0) {
31 std::cerr <<
"\033[31mCaught error: Division by 0. The method will diverge\033[0m" << std::endl;
33 double new_point = iter_two(0) - (pow(iter_two(0) - iter_one(0), 2) / denominator);
34 return {new_point, function(new_point)};
39 std::function<
double(
double)> der)
46 double denominator = derivative(previous_iteration(0));
47 if (denominator == 0) {
48 std::cerr <<
"\033[31mCaught error: Division by 0. The method will diverge\033[0m" << std::endl;
50 double new_point = previous_iteration(0) - previous_iteration(1) / denominator;
51 double new_eval = this->function(new_point);
52 return {new_point, new_eval};
57 std::function<
double(
double)> g_fun)
64 double new_point = this->fixed_point_function(previous_iteration(0));
65 double new_eval = this->function(new_point);
66 return {new_point, new_eval};
79 double numerator = this->iter_zero - this->iter_minus_1;
80 double denominator = last_iter(1) - this->function(this->iter_minus_1);
81 if (denominator == 0) {
82 std::cerr <<
"\033[31mCaught error: Division by 0. The method will diverge\033[0m" << std::endl;
84 double new_point = this->iter_zero - last_iter(1) * numerator / denominator;
85 this->iter_minus_1 = this->iter_zero;
86 this->iter_zero = new_point;
87 return {new_point, this->function(new_point)};
101 if (this->function(left_edge) == 0) {
102 return {left_edge, this->function(left_edge)};
104 if (this->function(right_edge) == 0) {
105 return {right_edge, this->function(right_edge)};
107 double x_new = (this->left_edge + this->right_edge) / 2;
108 if (this->function(x_new) * this->function(this->left_edge) < 0) {
109 this->right_edge = x_new;
111 this->left_edge = x_new;
113 return {x_new, this->function(x_new)};
The specialized Stepper to compute a step with the Bisection Method.
Definition stepper_def.hpp:136
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with Bisection. Let left_edge = a,...
BisectionStepper(std::function< double(double)> fun, bool aitken_mode, Eigen::Vector2d _int)
Constructor of a BisectionStepper object.
double right_edge
Bounds of the interval to use (updated at each step)
Definition stepper_def.hpp:138
double left_edge
Definition stepper_def.hpp:138
The specialized Stepper to compute a step with the Chords Method (also called Secants in literature)
Definition stepper_def.hpp:110
double iter_zero
The two previous guesses required at each iteration.
Definition stepper_def.hpp:112
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with Chords.
ChordsStepper(std::function< double(double)> fun, bool aitken_mode, Eigen::Vector2d _int)
Constructor for the ChordsStepper class.
double iter_minus_1
Definition stepper_def.hpp:112
The specialized Stepper to compute a step with the Fixed Point method.
Definition stepper_def.hpp:87
FixedPointStepper(std::function< double(double)> fun, bool aitken_mode, std::function< double(double)> g_fun)
The specialized constructor - initializes the function and the fixed point function.
std::function< double(double)> fixed_point_function
tores the fixed point to use in the steps
Definition stepper_def.hpp:89
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with FP.
The specialized Stepper to compute a step with the Newton-Raphson method.
Definition stepper_def.hpp:65
std::function< double(double)> derivative
Stores the derivative of the function.
Definition stepper_def.hpp:67
Eigen::Vector2d compute_step(Eigen::Vector2d previous_iteration) override
Specialized method to compute and return a new step with NR.
NewtonRaphsonStepper(std::function< double(double)> fun, bool aitken_mode, std::function< double(double)> der)
The specialized constructor - initializes the function and the derivative.
The virtual mother stepper class which defines constructor and method in common for all the methods.
Definition stepper_def.hpp:24
Eigen::Vector2d step(Eigen::Vector2d previous_step)
Method handling all the steps involved in computing the new guess.
Definition stepper.hpp:17
Eigen::Vector2d aitken_step(Eigen::Vector2d previous_iter)
Method to handle the computation of a step using Aitken's acceleration.
Definition stepper.hpp:26
StepperBase(std::function< double(double)> fun, bool aitken_mode)
Constructor for virtual Stepper class, which will be inherited by the daughters.
Definition stepper.hpp:11
Contains definitions for all the Classes Stepper to compute steps of numerical methods to find the ro...