![]() |
Open CASCADE Technology Reference Manual 8.0.0
|
Root finding algorithms for scalar functions. More...
Data Structures | |
| struct | AllRootsResult |
| Result for all roots finder including null intervals. More... | |
| struct | MultipleBrentValueWrapper |
| Brent wrapper that adapts a Value-only function for offset root finding. More... | |
| struct | MultipleConfig |
| Configuration for multiple root finding. More... | |
| struct | MultipleDerivativeValueWrapper |
| Wrapper exposing a function derivative through the Value() contract required by Brent. More... | |
| struct | MultipleGetRootValueFn |
| Evaluates original (non-offset) function value at a root point via Value interface. More... | |
| struct | MultipleGetValueFn |
| Returns the sampled value at a given index from a math_Vector. More... | |
| struct | MultipleNoExtraHandler |
| No-op interval handler for functions without derivative. More... | |
| struct | MultipleResult |
| Result for multiple root finding. Contains all found roots sorted in ascending order. More... | |
| struct | MultipleSampleValueFn |
| Samples a Value-only function and stores f(x)-offset into a math_Vector. More... | |
| struct | NullInterval |
| Represents an interval where the function is null (within tolerance). More... | |
| struct | TrigResult |
| Result for trigonometric equation solver. More... | |
Functions | |
| template<typename Func > | |
| MultipleResult | FindMultipleRoots (Func &theFunc, double theA, double theB, int theNbSamples, double theEpsX, double theEpsF, double theOffset=0.0) |
| Helper function to find multiple roots with offset. | |
| template<typename Func > | |
| AllRootsResult | FindAllRootsWithIntervals (Func &theFunc, const math_Vector &theSamples, double theEpsX=1.0e-10, double theEpsF=1.0e-10, double theEpsNul=1.0e-10) |
| Find all roots of a function using sampling and refinement. | |
| template<typename Func > | |
| AllRootsResult | FindAllRootsWithIntervals (Func &theFunc, double theA, double theB, int theNbSamples, double theEpsX=1.0e-10, double theEpsF=1.0e-10, double theEpsNul=1.0e-10) |
| Find all roots using uniform sampling. | |
| template<typename Function > | |
| MathUtils::ScalarResult | Bisection (Function &theFunc, double theLower, double theUpper, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Bisection method for root finding. Simple and robust, guaranteed to converge if a valid bracket is provided. Converges linearly, halving the interval at each step. | |
| template<typename Function > | |
| MathUtils::ScalarResult | BisectionNewton (Function &theFunc, double theLower, double theUpper, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Hybrid bisection-Newton method. Combines the robustness of bisection with the speed of Newton's method. Uses Newton step when it stays within bracket, otherwise bisects. | |
| template<typename Function > | |
| MathUtils::ScalarResult | Brent (Function &theFunc, double theLower, double theUpper, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Brent's method for root finding. Combines bisection, secant, and inverse quadratic interpolation. Guaranteed to converge if a valid bracket is provided. | |
| template<typename Function > | |
| MultipleResult | FindAllRoots (Function &theFunc, double theLower, double theUpper, const MultipleConfig &theConfig=MultipleConfig()) |
| Finds all real roots of a function within the range [theLower, theUpper]. Uses uniform sampling to detect sign changes, then refines each root using Brent's method. | |
| template<typename Function > | |
| MultipleResult | FindAllRootsWithDerivative (Function &theFunc, double theLower, double theUpper, const MultipleConfig &theConfig=MultipleConfig()) |
| Finds all real roots of a function with derivative within range [theLower, theUpper]. Can also detect extrema where function touches zero without crossing. | |
| template<typename Function > | |
| MultipleResult | FindAllRoots (Function &theFunc, double theLower, double theUpper, int theNbSamples) |
| Convenience alias using default configuration. | |
| void | SortRoots (MultipleResult &theResult) |
| In-place insertion sort of roots and corresponding values by ascending root value. | |
| void | AddRoot (MultipleResult &theResult, double theEpsX, double theRoot, double theValue) |
| Helper to add a root if it is not a duplicate of an already found root. | |
| double | EffectiveXTolerance (double theLower, double theUpper, double theXTolerance) |
| Compute the minimal X tolerance compatible with the established multi-root behavior. | |
| template<typename Function > | |
| bool | EvaluateValue (Function &theFunc, double theX, double &theValue) |
| Evaluate the original function value. | |
| template<typename Function > | |
| bool | EvaluateShiftedValue (Function &theFunc, double theX, double theOffset, double &theValue) |
| Evaluate the function value shifted by the requested offset. | |
| template<typename Function > | |
| bool | EvaluateShiftedValues (Function &theFunc, double theX, double theOffset, double &theValue, double &theDerivative) |
| Evaluate the function value and derivative, then shift the value by the requested offset. | |
| template<typename Function > | |
| bool | RefineBracketedRoot (Function &theFunc, double theOffset, double theX1, double theY1, double theX2, double theY2, double theTolerance, double theEpsX, MultipleResult &theResult) |
| Refine a bracketed sign change using the same Brent/Newton sequence as math_FunctionRoots. | |
| template<typename Function > | |
| MultipleResult | FindAllRootsWithDerivativeImpl (Function &theFunc, double theLower, double theUpper, const MultipleConfig &theConfig) |
| Derivative-aware implementation mirroring the proven math_FunctionRoots heuristics while operating on the modern callable-based MathRoot API. | |
| template<typename SampleFn , typename GetValueFn , typename BrentWrapperT , typename GetRootValueFn , typename IntervalExtraFn > | |
| MultipleResult | FindAllRootsImpl (double theLower, double theUpper, const MultipleConfig &theConfig, SampleFn theSampleFn, GetValueFn theGetValue, BrentWrapperT &theBrentWrapper, GetRootValueFn theGetRootValue, IntervalExtraFn theIntervalExtra) |
| Core implementation for finding all roots in an interval. Shared logic for both Value-only and Values (with derivative) interfaces. | |
| template<typename Function > | |
| MathUtils::ScalarResult | Newton (Function &theFunc, double theGuess, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Newton-Raphson root finding algorithm. Finds x such that f(x) = 0 using Newton's method with derivative. | |
| template<typename Function > | |
| MathUtils::ScalarResult | NewtonBounded (Function &theFunc, double theGuess, double theLower, double theUpper, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Newton-Raphson with bounds checking. Falls back to bisection step if Newton step goes outside bounds. More robust than pure Newton for ill-conditioned problems. | |
| template<typename Function > | |
| MathUtils::ScalarResult | Secant (Function &theFunc, double theX0, double theX1, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Secant method for root finding. Does not require derivative, uses finite difference approximation. Converges superlinearly (order ~1.618, the golden ratio). | |
| template<typename Function > | |
| MathUtils::ScalarResult | SecantAuto (Function &theFunc, double theX0, const MathUtils::Config &theConfig=MathUtils::Config()) |
| Secant method with automatic initial points. Creates second point by small perturbation of the initial guess. | |
| TrigResult | Trigonometric (double theA, double theB, double theC, double theD, double theE, double theInfBound=0.0, double theSupBound=THE_2PI, double theEps=1.5e-12) |
| Solve trigonometric equation: a*cos^2(x) + 2*b*cos(x)*sin(x) + c*cos(x) + d*sin(x) + e = 0. | |
| TrigResult | TrigonometricLinear (double theD, double theE, double theInfBound=0.0, double theSupBound=THE_2PI) |
| Solve linear trigonometric equation: d*sin(x) + e = 0. | |
| TrigResult | TrigonometricCDE (double theC, double theD, double theE, double theInfBound=0.0, double theSupBound=THE_2PI) |
| Solve trigonometric equation: c*cos(x) + d*sin(x) + e = 0. | |
Root finding algorithms for scalar functions.
|
inline |
Helper to add a root if it is not a duplicate of an already found root.
| MathUtils::ScalarResult MathRoot::Bisection | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Bisection method for root finding. Simple and robust, guaranteed to converge if a valid bracket is provided. Converges linearly, halving the interval at each step.
Algorithm:
| Function | type with Value(double theX, double& theF) method |
| theFunc | function to find root of |
| theLower | lower bound of bracket |
| theUpper | upper bound of bracket |
| theConfig | solver configuration |
| MathUtils::ScalarResult MathRoot::BisectionNewton | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Hybrid bisection-Newton method. Combines the robustness of bisection with the speed of Newton's method. Uses Newton step when it stays within bracket, otherwise bisects.
| Function | type with Values(double theX, double& theF, double& theDf) method |
| theFunc | function with value and derivative |
| theLower | lower bound of bracket |
| theUpper | upper bound of bracket |
| theConfig | solver configuration |
| MathUtils::ScalarResult MathRoot::Brent | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Brent's method for root finding. Combines bisection, secant, and inverse quadratic interpolation. Guaranteed to converge if a valid bracket is provided.
Algorithm:
| Function | type with Value(double theX, double& theF) method |
| theFunc | function to find root of |
| theLower | lower bound of bracket (f(theLower) and f(theUpper) must have opposite signs) |
| theUpper | upper bound of bracket |
| theConfig | solver configuration |
|
inline |
Compute the minimal X tolerance compatible with the established multi-root behavior.
| bool MathRoot::EvaluateShiftedValue | ( | Function & | theFunc, |
| double | theX, | ||
| double | theOffset, | ||
| double & | theValue ) |
Evaluate the function value shifted by the requested offset.
| Function | type with Value(double theX, double& theF) method |
| bool MathRoot::EvaluateShiftedValues | ( | Function & | theFunc, |
| double | theX, | ||
| double | theOffset, | ||
| double & | theValue, | ||
| double & | theDerivative ) |
Evaluate the function value and derivative, then shift the value by the requested offset.
| Function | type with Values(double theX, double& theF, double& theDF) method |
| bool MathRoot::EvaluateValue | ( | Function & | theFunc, |
| double | theX, | ||
| double & | theValue ) |
Evaluate the original function value.
| Function | type with Value(double theX, double& theF) method |
| MultipleResult MathRoot::FindAllRoots | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| const MultipleConfig & | theConfig = MultipleConfig() ) |
Finds all real roots of a function within the range [theLower, theUpper]. Uses uniform sampling to detect sign changes, then refines each root using Brent's method.
Algorithm:
| Function | type with Value(double theX, double& theF) method |
| theFunc | function object to find roots of |
| theLower | lower bound of search interval |
| theUpper | upper bound of search interval |
| theConfig | configuration parameters |
| MultipleResult MathRoot::FindAllRoots | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| int | theNbSamples ) |
Convenience alias using default configuration.
| Function | type with Value(double, double&) method |
| theFunc | function to find roots of |
| theLower | lower bound |
| theUpper | upper bound |
| theNbSamples | number of sample points |
| MultipleResult MathRoot::FindAllRootsImpl | ( | double | theLower, |
| double | theUpper, | ||
| const MultipleConfig & | theConfig, | ||
| SampleFn | theSampleFn, | ||
| GetValueFn | theGetValue, | ||
| BrentWrapperT & | theBrentWrapper, | ||
| GetRootValueFn | theGetRootValue, | ||
| IntervalExtraFn | theIntervalExtra ) |
Core implementation for finding all roots in an interval. Shared logic for both Value-only and Values (with derivative) interfaces.
| SampleFn | callable (int theIndex, double theX) -> bool |
| GetValueFn | callable (int theIndex) -> double, returns f(x)-offset at sample |
| BrentWrapperT | type with Value(double, double&) for Brent root finding |
| GetRootValueFn | callable (double theX) -> double, returns original f(x) |
| IntervalExtraFn | callable (int, x0, x1, f0, f1, result, epsX) -> void |
| MultipleResult MathRoot::FindAllRootsWithDerivative | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| const MultipleConfig & | theConfig = MultipleConfig() ) |
Finds all real roots of a function with derivative within range [theLower, theUpper]. Can also detect extrema where function touches zero without crossing.
This version uses derivative information for better extrema detection.
| Function | type with Values(double theX, double& theF, double& theDF) method |
| theFunc | function object with derivative |
| theLower | lower bound of search interval |
| theUpper | upper bound of search interval |
| theConfig | configuration parameters |
| MultipleResult MathRoot::FindAllRootsWithDerivativeImpl | ( | Function & | theFunc, |
| double | theLower, | ||
| double | theUpper, | ||
| const MultipleConfig & | theConfig ) |
Derivative-aware implementation mirroring the proven math_FunctionRoots heuristics while operating on the modern callable-based MathRoot API.
| Function | type with Value() and Values() methods |
| AllRootsResult MathRoot::FindAllRootsWithIntervals | ( | Func & | theFunc, |
| const math_Vector & | theSamples, | ||
| double | theEpsX = 1.0e-10, | ||
| double | theEpsF = 1.0e-10, | ||
| double | theEpsNul = 1.0e-10 ) |
Find all roots of a function using sampling and refinement.
Uses a sample of the function to find:
The algorithm:
| Func | function type with:
|
| theFunc | function with derivative to analyze |
| theSamples | sample points array |
| theEpsX | tolerance for root x-value |
| theEpsF | tolerance for function value at root |
| theEpsNul | tolerance for null interval detection |
| AllRootsResult MathRoot::FindAllRootsWithIntervals | ( | Func & | theFunc, |
| double | theA, | ||
| double | theB, | ||
| int | theNbSamples, | ||
| double | theEpsX = 1.0e-10, | ||
| double | theEpsF = 1.0e-10, | ||
| double | theEpsNul = 1.0e-10 ) |
Find all roots using uniform sampling.
| Func | function type with Value and Values methods |
| theFunc | function with derivative |
| theA | interval start |
| theB | interval end |
| theNbSamples | number of sample points |
| theEpsX | tolerance for root x-value |
| theEpsF | tolerance for function value |
| theEpsNul | tolerance for null interval detection |
| MultipleResult MathRoot::FindMultipleRoots | ( | Func & | theFunc, |
| double | theA, | ||
| double | theB, | ||
| int | theNbSamples, | ||
| double | theEpsX, | ||
| double | theEpsF, | ||
| double | theOffset = 0.0 ) |
Helper function to find multiple roots with offset.
| Func | function type |
| theFunc | function to analyze |
| theA | interval start |
| theB | interval end |
| theNbSamples | number of sample points |
| theEpsX | tolerance for root x-value |
| theEpsF | tolerance for function value |
| theOffset | offset value (find roots of f(x) - offset = 0) |
| MathUtils::ScalarResult MathRoot::Newton | ( | Function & | theFunc, |
| double | theGuess, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Newton-Raphson root finding algorithm. Finds x such that f(x) = 0 using Newton's method with derivative.
Algorithm: x_{n+1} = x_n - f(x_n) / f'(x_n)
Requires a function providing both value and derivative. Converges quadratically near the root for simple roots.
| Function | type with Values(double theX, double& theF, double& theDf) method returning bool (true if evaluation succeeded) |
| theFunc | function object providing value and derivative |
| theGuess | initial guess for the root |
| theConfig | solver configuration (tolerances, max iterations) |
| MathUtils::ScalarResult MathRoot::NewtonBounded | ( | Function & | theFunc, |
| double | theGuess, | ||
| double | theLower, | ||
| double | theUpper, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Newton-Raphson with bounds checking. Falls back to bisection step if Newton step goes outside bounds. More robust than pure Newton for ill-conditioned problems.
| Function | type with Values(double theX, double& theF, double& theDf) method |
| theFunc | function object providing value and derivative |
| theGuess | initial guess for the root |
| theLower | lower bound of search interval |
| theUpper | upper bound of search interval |
| theConfig | solver configuration |
| bool MathRoot::RefineBracketedRoot | ( | Function & | theFunc, |
| double | theOffset, | ||
| double | theX1, | ||
| double | theY1, | ||
| double | theX2, | ||
| double | theY2, | ||
| double | theTolerance, | ||
| double | theEpsX, | ||
| MultipleResult & | theResult ) |
Refine a bracketed sign change using the same Brent/Newton sequence as math_FunctionRoots.
| Function | type with Value() and Values() methods |
| MathUtils::ScalarResult MathRoot::Secant | ( | Function & | theFunc, |
| double | theX0, | ||
| double | theX1, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Secant method for root finding. Does not require derivative, uses finite difference approximation. Converges superlinearly (order ~1.618, the golden ratio).
Algorithm:
| Function | type with Value(double theX, double& theF) method |
| theFunc | function object providing only value |
| theX0 | first initial point |
| theX1 | second initial point (different from theX0) |
| theConfig | solver configuration |
| MathUtils::ScalarResult MathRoot::SecantAuto | ( | Function & | theFunc, |
| double | theX0, | ||
| const MathUtils::Config & | theConfig = MathUtils::Config() ) |
Secant method with automatic initial points. Creates second point by small perturbation of the initial guess.
| Function | type with Value(double theX, double& theF) method |
| theFunc | function object providing only value |
| theX0 | initial guess |
| theConfig | solver configuration |
|
inline |
In-place insertion sort of roots and corresponding values by ascending root value.
|
inline |
Solve trigonometric equation: a*cos^2(x) + 2*b*cos(x)*sin(x) + c*cos(x) + d*sin(x) + e = 0.
Uses half-angle substitution t = tan(x/2) to convert to polynomial:
Resulting polynomial is of degree 4, 3, or 2 depending on coefficients. Roots are filtered to lie within [theInfBound, theSupBound].
| theA | coefficient of cos^2(x) |
| theB | coefficient of cos(x)*sin(x) (equation uses 2*b) |
| theC | coefficient of cos(x) |
| theD | coefficient of sin(x) |
| theE | constant term |
| theInfBound | lower bound for roots (default 0) |
| theSupBound | upper bound for roots (default 2*PI) |
| theEps | tolerance for coefficient comparison |
|
inline |
Solve trigonometric equation: c*cos(x) + d*sin(x) + e = 0.
| theC | coefficient of cos(x) |
| theD | coefficient of sin(x) |
| theE | constant term |
| theInfBound | lower bound for roots |
| theSupBound | upper bound for roots |
|
inline |
Solve linear trigonometric equation: d*sin(x) + e = 0.
| theD | coefficient of sin(x) |
| theE | constant term |
| theInfBound | lower bound for roots |
| theSupBound | upper bound for roots |