Belle II Software development
|
Helper class to calculate roots for the function f(x) = sin x - slope * x - intercept. More...
#include <SinEqLine.h>
Public Member Functions | |
SinEqLine () | |
Default constructor initializing slope and intercept to zero. | |
SinEqLine (const Line2D &line2D) | |
Constructor taking the line that shall be superimposed with the sin curve. | |
SinEqLine (const double slope, const double intercept) | |
Constructor taking the slope and intercept of the line that shall be superimposed with the sin curve. | |
double | map (const double x) const |
Interpreting as the function f this method carries out the translation from x to y coordinates. | |
double | gradient (const double x) const |
Interpreting as the function f this method calculates the gradient as need in Newtons algorithms. | |
int | getIHalfPeriod (const double x) const |
Returns the half period index in which the x position is located. | |
double | computeSmallestPositiveRoot (int maxIHalfPeriod=5) const |
double | computeRootLargerThanExtemumInHalfPeriod (int iHalfPeriod) const |
Computes the solution that is addressed by the given half period index. | |
double | computeRootForLargeSlope () const |
Compute single solution in the case that fabs(slope) >= 1. | |
double | computeRootInInterval (double lowerX, double upperX) const |
Computes the solution in between the given x values. The x values are generally chosen consecutive local extremes. | |
double | computeExtremumXInHalfPeriod (int iHalfPeriod) const |
Get the local extremum that is located in the half period indicated by the given index. | |
bool | hasLargeSlope () const |
Indicates that the slope is so large such that the function has no local extrema. | |
double | getSlope () const |
Getter for the slope. | |
double | getIntercept () const |
Getter for the intercept. | |
Static Public Member Functions | |
static bool | changesSign (const Vector2D &lower, const Vector2D &upper) |
Checks if the function changes sign in the interval. | |
static EIncDec | getEIncDec (const Vector2D &lower, const Vector2D &upper) |
Determines if the function is increasing or decreasing in the interval. | |
static int | getIPeriodFromIHalfPeriod (int iHalfPeriod) |
Helper function to translate the index of the half period to index of the containing period. | |
Private Member Functions | |
double | newtonX (const Vector2D &pos) const |
Shrinking method of the newton algorithm return the next candidate root. | |
Static Private Member Functions | |
static double | secantX (const Vector2D &lower, const Vector2D &upper) |
Fall back shrinking method to the secant algorithm. | |
static double | middleX (const Vector2D &lower, const Vector2D &upper) |
Simple fall back shrinking method using trivial division of the interval. | |
static bool | updateBounds (Vector2D &lower, Vector2D &upper, const Vector2D &next) |
Replaces the lower or upper bound inplace if the next candidate position is valid and within the interval. Returns true on success. | |
static bool | isBetween (const Vector2D &lower, const Vector2D &next, const Vector2D &upper) |
Check is next position is within the interval given by lower and upper. | |
static bool | isConverged (const Vector2D &lower, const Vector2D &upper) |
Check if the interval has shrunk close enough to the solution. | |
static double | getConvergedBound (const Vector2D &lower, const Vector2D &upper) |
Returns the better solution x from the bounds of the interval. | |
Private Attributes | |
double | m_slope |
Memory for the slope. | |
double | m_intercept |
Memory for the intercept. | |
Helper class to calculate roots for the function f(x) = sin x - slope * x - intercept.
Solves the equation sin x = slope * x + intercept by Newton's method on the function f(x) = sin x - slope * x - intercept. There can be zero, infinitely many solutions and anything in-between depending on the value of slope and intercept. To find solutions we exploit that the local extrema of the function f(x) can be found easily and that maximally one solutions can be found between consecutive extrema. There is exactly one local extremum in each half period of sin(x) and local extrema are therefore addressed by there half period index. Each possible solution of the equation is than addressed by the index of the closest smaller local extrema. However only a range of indices corresponds to realized solutions. For non existent solutions NAN is returned. Note that for fabs(slope) >= 1 there are no more local maxima. In this case only a single solution exists, which is always returned for any index.
Definition at line 36 of file SinEqLine.h.
|
inline |
Default constructor initializing slope and intercept to zero.
Definition at line 40 of file SinEqLine.h.
Constructor taking the line that shall be superimposed with the sin curve.
Definition at line 47 of file SinEqLine.h.
|
inline |
Constructor taking the slope and intercept of the line that shall be superimposed with the sin curve.
Definition at line 53 of file SinEqLine.h.
Checks if the function changes sign in the interval.
Definition at line 129 of file SinEqLine.h.
double computeExtremumXInHalfPeriod | ( | int | iHalfPeriod | ) | const |
Get the local extremum that is located in the half period indicated by the given index.
Definition at line 185 of file SinEqLine.cc.
double computeRootForLargeSlope | ( | ) | const |
Compute single solution in the case that fabs(slope) >= 1.
Definition at line 50 of file SinEqLine.cc.
double computeRootInInterval | ( | double | lowerX, |
double | upperX | ||
) | const |
Computes the solution in between the given x values. The x values are generally chosen consecutive local extremes.
Checks if convergence criterium has been met. For instance if one bound is already exactly at the root.
Checks if the function changes sign in the interval
Definition at line 67 of file SinEqLine.cc.
double computeRootLargerThanExtemumInHalfPeriod | ( | int | iHalfPeriod | ) | const |
Computes the solution that is addressed by the given half period index.
Definition at line 38 of file SinEqLine.cc.
double computeSmallestPositiveRoot | ( | int | maxIHalfPeriod = 5 | ) | const |
Smallest positive root might before the first positive extremum
Most of the time to should be sufficient to look for the root in the first two half periods. So we spell out this case explicitly.
Check if the solution returned is positive, that implies that it is not NAN.
Definition at line 17 of file SinEqLine.cc.
|
inlinestaticprivate |
Returns the better solution x from the bounds of the interval.
Definition at line 110 of file SinEqLine.h.
Determines if the function is increasing or decreasing in the interval.
Definition at line 133 of file SinEqLine.h.
|
inline |
Returns the half period index in which the x position is located.
Definition at line 68 of file SinEqLine.h.
|
inline |
|
inlinestatic |
Helper function to translate the index of the half period to index of the containing period.
Definition at line 151 of file SinEqLine.h.
|
inline |
|
inline |
Interpreting as the function f this method calculates the gradient as need in Newtons algorithms.
Definition at line 64 of file SinEqLine.h.
|
inline |
Indicates that the slope is so large such that the function has no local extrema.
Definition at line 156 of file SinEqLine.h.
|
inlinestaticprivate |
Check is next position is within the interval given by lower and upper.
Definition at line 100 of file SinEqLine.h.
Check if the interval has shrunk close enough to the solution.
Definition at line 104 of file SinEqLine.h.
|
inline |
Interpreting as the function f this method carries out the translation from x to y coordinates.
Definition at line 60 of file SinEqLine.h.
Simple fall back shrinking method using trivial division of the interval.
Definition at line 134 of file SinEqLine.cc.
|
private |
Shrinking method of the newton algorithm return the next candidate root.
Definition at line 144 of file SinEqLine.cc.
Fall back shrinking method to the secant algorithm.
Definition at line 139 of file SinEqLine.cc.
Replaces the lower or upper bound inplace if the next candidate position is valid and within the interval. Returns true on success.
Only update if the next point is in-between the lower and upper bound
Definition at line 149 of file SinEqLine.cc.
|
private |
Memory for the intercept.
Definition at line 172 of file SinEqLine.h.
|
private |
Memory for the slope.
Definition at line 169 of file SinEqLine.h.