Open CASCADE Technology Reference Manual 8.0.0
Loading...
Searching...
No Matches
Namespaces | Data Structures | Functions
MathSys Namespace Reference

Shared types for specialized small-dimension Newton solvers. More...

Namespaces

namespace  detail
 

Data Structures

struct  LMConfig
 Configuration for Levenberg-Marquardt algorithm. Extends base Config with damping parameter settings. More...
 
struct  NewtonBoundsN
 Box bounds for N-dimensional solver. More...
 
struct  NewtonOptions
 Solver options for small-dimension Newton methods. More...
 
struct  NewtonResultN
 Result of N-dimensional Newton solver. More...
 

Functions

template<typename FuncSetType >
VectorResult Newton (FuncSetType &theFunc, const math_Vector &theStart, const math_Vector &theTolX, double theTolF, size_t theMaxIter=100)
 Newton-Raphson method for solving systems of nonlinear equations.
 
template<typename FuncSetType >
VectorResult NewtonBounded (FuncSetType &theFunc, const math_Vector &theStart, const math_Vector &theInfBound, const math_Vector &theSupBound, const math_Vector &theTolX, double theTolF, size_t theMaxIter=100)
 Newton-Raphson method with bounds constraints.
 
template<typename FuncSetType >
VectorResult Newton (FuncSetType &theFunc, const math_Vector &theStart, double theTolX, double theTolF, size_t theMaxIter=100)
 Simplified Newton method with uniform tolerances.
 
template<typename Function >
NewtonResultN< 2 > Solve2D (const Function &theFunc, const std::array< double, 2 > &theX0, const NewtonBoundsN< 2 > &theBounds, const NewtonOptions &theOptions=NewtonOptions())
 Solve a general 2x2 nonlinear system by Newton iteration. Function contract: bool operator()(double u, double v, double f[2], double j[2][2]) const;.
 
template<typename Function >
NewtonResultN< 2 > Solve2DSymmetric (const Function &theFunc, const std::array< double, 2 > &theX0, const NewtonBoundsN< 2 > &theBounds, const NewtonOptions &theOptions=NewtonOptions())
 Solve a 2x2 system with symmetric Jacobian by robust Newton iteration. Function contract: bool ValueAndJacobian(double u, double v, double& f1, double& f2, double& j11, double& j12, double& j22) const; bool Value(double u, double v, double& f1, double& f2) const; // required if line search is enabled.
 
template<typename Function >
NewtonResultN< 3 > Solve3D (const Function &theFunc, const std::array< double, 3 > &theX0, const NewtonBoundsN< 3 > &theBounds, const NewtonOptions &theOptions=NewtonOptions())
 Solve a 3x3 nonlinear system by Newton iteration with bounds.
 
template<typename CurveEvaluator , typename SurfaceEvaluator >
NewtonResultN< 3 > SolveCurveSurfaceExtrema3D (const CurveEvaluator &theCurve, const SurfaceEvaluator &theSurface, const std::array< double, 3 > &theX0, const NewtonBoundsN< 3 > &theBounds, const NewtonOptions &theOptions=NewtonOptions())
 Optimized 3D Newton solver for curve-surface extrema.
 
template<typename Function >
NewtonResultN< 4 > Solve4D (const Function &theFunc, const std::array< double, 4 > &theX0, const NewtonBoundsN< 4 > &theBounds, const NewtonOptions &theOptions=NewtonOptions())
 Solve a 4x4 nonlinear system by Newton iteration with bounds.
 
template<typename SurfaceEvaluator1 , typename SurfaceEvaluator2 >
NewtonResultN< 4 > SolveSurfaceSurfaceExtrema4D (const SurfaceEvaluator1 &theSurf1, const SurfaceEvaluator2 &theSurf2, const std::array< double, 4 > &theX0, const NewtonBoundsN< 4 > &theBounds, const NewtonOptions &theOptions=NewtonOptions())
 Optimized 4D Newton solver for surface-surface extrema.
 
template<typename FuncSetType >
VectorResult LevenbergMarquardt (FuncSetType &theFunc, const math_Vector &theStart, const LMConfig &theConfig=LMConfig())
 Levenberg-Marquardt algorithm for nonlinear least squares.
 
template<typename FuncSetType >
VectorResult LevenbergMarquardtBounded (FuncSetType &theFunc, const math_Vector &theStart, const math_Vector &theInfBound, const math_Vector &theSupBound, const LMConfig &theConfig=LMConfig())
 Levenberg-Marquardt with bounds constraints.
 

Detailed Description

Shared types for specialized small-dimension Newton solvers.

Function Documentation

◆ LevenbergMarquardt()

template<typename FuncSetType >
VectorResult MathSys::LevenbergMarquardt ( FuncSetType & theFunc,
const math_Vector & theStart,
const LMConfig & theConfig = LMConfig() )

Levenberg-Marquardt algorithm for nonlinear least squares.

Minimizes ||F(X)||^2 where F is a vector function of vector X. Combines Gauss-Newton method (fast near minimum) with gradient descent (robust far from minimum) using adaptive damping.

Algorithm:

  1. Compute F(X) and Jacobian J at current point
  2. Solve (J^T*J + lambda*I) * dX = -J^T*F for correction dX
  3. If ||F(X+dX)||^2 < ||F(X)||^2: accept step, decrease lambda
  4. Otherwise: reject step, increase lambda
  5. Repeat until convergence
Template Parameters
FuncSetTypetype with NbVariables(), NbEquations(), Value(const math_Vector& X, math_Vector& F) and Derivatives(const math_Vector& X, math_Matrix& J) or Values(const math_Vector& X, math_Vector& F, math_Matrix& J)
Parameters
theFuncfunction set providing residuals and Jacobian
theStartinitial guess vector
theConfigLevenberg-Marquardt configuration
Returns
result containing solution vector if converged

◆ LevenbergMarquardtBounded()

template<typename FuncSetType >
VectorResult MathSys::LevenbergMarquardtBounded ( FuncSetType & theFunc,
const math_Vector & theStart,
const math_Vector & theInfBound,
const math_Vector & theSupBound,
const LMConfig & theConfig = LMConfig() )

Levenberg-Marquardt with bounds constraints.

Minimizes ||F(X)||^2 subject to theInfBound <= X <= theSupBound. Solution is clamped to bounds after each step.

Parameters
theFuncfunction set providing residuals and Jacobian
theStartinitial guess vector
theInfBoundlower bounds for solution
theSupBoundupper bounds for solution
theConfigLevenberg-Marquardt configuration
Returns
result containing solution vector if converged

◆ Newton() [1/2]

template<typename FuncSetType >
VectorResult MathSys::Newton ( FuncSetType & theFunc,
const math_Vector & theStart,
const math_Vector & theTolX,
double theTolF,
size_t theMaxIter = 100 )

Newton-Raphson method for solving systems of nonlinear equations.

Solves F(X) = 0 where F is a vector function of vector X. The method iteratively improves an initial guess by solving the linear system J(X)*dX = -F(X) where J is the Jacobian matrix.

Parameters
theFuncfunction set with derivatives (Jacobian)
theStartinitial guess vector
theTolXtolerance for solution change ||X(n+1) - X(n)|| < tolX
theTolFtolerance for function values ||F(X)|| < tolF
theMaxItermaximum number of iterations
Returns
result containing solution vector if converged

◆ Newton() [2/2]

template<typename FuncSetType >
VectorResult MathSys::Newton ( FuncSetType & theFunc,
const math_Vector & theStart,
double theTolX,
double theTolF,
size_t theMaxIter = 100 )

Simplified Newton method with uniform tolerances.

Parameters
theFuncfunction set with derivatives
theStartinitial guess vector
theTolXuniform tolerance for all variables
theTolFtolerance for function values
theMaxItermaximum number of iterations
Returns
result containing solution vector if converged

◆ NewtonBounded()

template<typename FuncSetType >
VectorResult MathSys::NewtonBounded ( FuncSetType & theFunc,
const math_Vector & theStart,
const math_Vector & theInfBound,
const math_Vector & theSupBound,
const math_Vector & theTolX,
double theTolF,
size_t theMaxIter = 100 )

Newton-Raphson method with bounds constraints.

Solves F(X) = 0 subject to InfBound <= X <= SupBound. If the Newton step would take X outside bounds, the solution is clamped to the boundary.

Parameters
theFuncfunction set with derivatives (Jacobian)
theStartinitial guess vector
theInfBoundlower bounds for solution
theSupBoundupper bounds for solution
theTolXtolerance for solution change
theTolFtolerance for function values
theMaxItermaximum number of iterations
Returns
result containing solution vector if converged

◆ Solve2D()

template<typename Function >
NewtonResultN< 2 > MathSys::Solve2D ( const Function & theFunc,
const std::array< double, 2 > & theX0,
const NewtonBoundsN< 2 > & theBounds,
const NewtonOptions & theOptions = NewtonOptions() )

Solve a general 2x2 nonlinear system by Newton iteration. Function contract: bool operator()(double u, double v, double f[2], double j[2][2]) const;.

◆ Solve2DSymmetric()

template<typename Function >
NewtonResultN< 2 > MathSys::Solve2DSymmetric ( const Function & theFunc,
const std::array< double, 2 > & theX0,
const NewtonBoundsN< 2 > & theBounds,
const NewtonOptions & theOptions = NewtonOptions() )

Solve a 2x2 system with symmetric Jacobian by robust Newton iteration. Function contract: bool ValueAndJacobian(double u, double v, double& f1, double& f2, double& j11, double& j12, double& j22) const; bool Value(double u, double v, double& f1, double& f2) const; // required if line search is enabled.

◆ Solve3D()

template<typename Function >
NewtonResultN< 3 > MathSys::Solve3D ( const Function & theFunc,
const std::array< double, 3 > & theX0,
const NewtonBoundsN< 3 > & theBounds,
const NewtonOptions & theOptions = NewtonOptions() )

Solve a 3x3 nonlinear system by Newton iteration with bounds.

Solves the system [F1, F2, F3] = [0, 0, 0] using Newton-Raphson iteration with Cramer's rule for the 3x3 linear system at each step.

The function type must be callable with signature:

bool operator()(double theX1, double theX2, double theX3,
double theF[3], double theJ[3][3]) const;
STL input iterator that wraps an OCCT More()/Next() iterator.
Definition NCollection_ForwardRange.hxx:142

where theF is the function values and theJ is the 3x3 Jacobian matrix.

Template Parameters
Functioncallable type (functor, lambda, or function pointer)
Parameters
[in]theFuncfunction to solve (provides F and Jacobian)
[in]theX0initial guess {x1, x2, x3}
[in]theBoundsbox bounds for each variable
[in]theOptionssolver options (tolerances, max iterations, etc.)
Returns
NewtonResultN<3> containing solution, status, and diagnostics

◆ Solve4D()

template<typename Function >
NewtonResultN< 4 > MathSys::Solve4D ( const Function & theFunc,
const std::array< double, 4 > & theX0,
const NewtonBoundsN< 4 > & theBounds,
const NewtonOptions & theOptions = NewtonOptions() )

Solve a 4x4 nonlinear system by Newton iteration with bounds.

Solves the system [F1, F2, F3, F4] = [0, 0, 0, 0] using Newton-Raphson iteration with Gaussian elimination for the 4x4 linear system at each step.

The function type must be callable with signature:

bool operator()(double theX1, double theX2, double theX3, double theX4,
double theF[4], double theJ[4][4]) const;

where theF is the function values and theJ is the 4x4 Jacobian matrix.

Template Parameters
Functioncallable type (functor, lambda, or function pointer)
Parameters
[in]theFuncfunction to solve (provides F and Jacobian)
[in]theX0initial guess {x1, x2, x3, x4}
[in]theBoundsbox bounds for each variable
[in]theOptionssolver options (tolerances, max iterations, etc.)
Returns
NewtonResultN<4> containing solution, status, and diagnostics

◆ SolveCurveSurfaceExtrema3D()

NewtonResultN< 3 > MathSys::SolveCurveSurfaceExtrema3D ( const CurveEvaluator & theCurve,
const SurfaceEvaluator & theSurface,
const std::array< double, 3 > & theX0,
const NewtonBoundsN< 3 > & theBounds,
const NewtonOptions & theOptions = NewtonOptions() )

Optimized 3D Newton solver for curve-surface extrema.

Specialized version for finding extrema between a curve C(t) and surface S(u,v). The function values are the gradient components of the squared distance:

  • F1 = (C-S) . dC/dt
  • F2 = (S-C) . dS/du
  • F3 = (S-C) . dS/dv
Template Parameters
CurveEvaluatortype providing D2(t, P, D1, D2) evaluation
SurfaceEvaluatortype providing D2(u, v, P, D1U, D1V, D2UU, D2VV, D2UV) evaluation
Parameters
[in]theCurvecurve evaluator
[in]theSurfacesurface evaluator
[in]theX0initial guess {t, u, v}
[in]theBoundsbox bounds for {t, u, v}
[in]theOptionssolver options
Returns
NewtonResultN<3> with t, u, v stored in X[0], X[1], X[2]

◆ SolveSurfaceSurfaceExtrema4D()

NewtonResultN< 4 > MathSys::SolveSurfaceSurfaceExtrema4D ( const SurfaceEvaluator1 & theSurf1,
const SurfaceEvaluator2 & theSurf2,
const std::array< double, 4 > & theX0,
const NewtonBoundsN< 4 > & theBounds,
const NewtonOptions & theOptions = NewtonOptions() )

Optimized 4D Newton solver for surface-surface extrema.

Specialized version for finding extrema between two surfaces S1(u1,v1) and S2(u2,v2). The function values are the gradient components of the squared distance:

  • F1 = (S1-S2) . dS1/dU1
  • F2 = (S1-S2) . dS1/dV1
  • F3 = (S2-S1) . dS2/dU2
  • F4 = (S2-S1) . dS2/dV2

The Jacobian has a special block structure with 2x2 blocks.

Template Parameters
SurfaceEvaluator1type providing D2 evaluation for first surface
SurfaceEvaluator2type providing D2 evaluation for second surface
Parameters
[in]theSurf1first surface evaluator
[in]theSurf2second surface evaluator
[in]theX0initial guess {u1, v1, u2, v2}
[in]theBoundsbox bounds for {u1, v1, u2, v2}
[in]theOptionssolver options
Returns
NewtonResultN<4> with u1, v1, u2, v2 stored in X[0..3]