2021-01-27 18:42:02 +00:00
|
|
|
#ifndef ROOTFINDER_HH
|
|
|
|
#define ROOTFINDER_HH
|
2020-12-17 21:58:29 +00:00
|
|
|
#include <iostream>
|
2020-10-29 17:30:38 +00:00
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
Negative = -1,
|
|
|
|
Unconstrained,
|
|
|
|
Positive
|
|
|
|
} SlopeConstraint;
|
|
|
|
|
|
|
|
class RootFinder {
|
|
|
|
public:
|
|
|
|
void init();
|
2020-10-30 22:26:56 +00:00
|
|
|
void init( double tolerance, SlopeConstraint constraint);
|
2020-10-29 17:30:38 +00:00
|
|
|
RootFinder();
|
|
|
|
RootFinder (double tolerance, SlopeConstraint constraint);
|
|
|
|
double find_roots( double x, double f_error );
|
2020-12-17 21:58:29 +00:00
|
|
|
friend std::ostream& operator<<(std::ostream& os, const RootFinder& rf);
|
2020-10-29 17:30:38 +00:00
|
|
|
private:
|
|
|
|
double f_upper;
|
|
|
|
double x_upper;
|
|
|
|
bool upper_set;
|
|
|
|
double f_lower;
|
|
|
|
double x_lower;
|
|
|
|
bool lower_set;
|
|
|
|
double prev_f_error;
|
|
|
|
double f_error_tol;
|
|
|
|
int iterations;
|
|
|
|
SlopeConstraint slope_constraint;
|
|
|
|
SlopeConstraint f_slope;
|
|
|
|
};
|
2021-01-27 18:42:02 +00:00
|
|
|
#endif /* ROOTFINDER_HH */
|