🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
UnarySolver.hpp
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstMath/Function.hpp"
25#include "AstMath/SolverStats.h"
26#include <type_traits>
27
28
29AST_NAMESPACE_BEGIN
30
31
32
39AST_MATH_CAPI bool aIsClose(double a, double b, double relTol = kDefaultRelTol, double absTol = kDefaultAbsTol);
40
41
42
45class AST_MATH_API IUnarySolver
46{
47public:
48 virtual ~IUnarySolver() = default;
49
55 virtual errc_t solve(UnaryScalarFunc& func, double min, double max, double& result) = 0;
56};
57
58
62class AST_MATH_API UnarySolver: public IUnarySolver
63{
64public:
65 using IUnarySolver::solve;
66
72 UnarySolver(double relTol, double absTol, int maxIter);
73
76 explicit UnarySolver(double absTol);
77
78 ~UnarySolver() override = default;
79
81 double getRelTol() const{return relTol_;};
83 double getAbsTol() const{return absTol_;};
85 int getMaxIter() const{return maxIter_;};
86
88 void setRelTol(double relTol){relTol_ = relTol;};
90 void setAbsTol(double absTol){absTol_ = absTol;};
92 void setMaxIter(int maxIter){maxIter_ = maxIter;};
93
95 const SolverStats& getStats() const{return stats_;};
96
103 template<typename Func>
104 typename std::enable_if<!std::is_base_of<UnaryScalarFunc, typename std::remove_pointer<Func>::type>::value, errc_t>::type
105 solve(Func func, double min, double max, double& result) {
106 UnaryScalarGenericFunc<Func> adapter(std::move(func));
107 return this->solve(adapter, min, max, result);
108 }
109protected:
110 static double unarycfunc(double x, void* params);
111protected:
112 double relTol_;
113 double absTol_;
115 SolverStats stats_{};
116};
117
118using UnaryScalarSolver = UnarySolver;
119
120
121AST_NAMESPACE_END
一元方程求解器接口
定义 UnarySolver.hpp:46
virtual errc_t solve(UnaryScalarFunc &func, double min, double max, double &result)=0
求解一元方程
一元标量值函数
定义 UnaryScalarFunc.hpp:31
泛型一元函数适配器
定义 UnaryScalarFunc.hpp:48
一元方程求解器
定义 UnarySolver.hpp:63
int maxIter_
最大迭代次数
定义 UnarySolver.hpp:114
void setRelTol(double relTol)
设置相对误差容限
定义 UnarySolver.hpp:88
double absTol_
绝对误差容限
定义 UnarySolver.hpp:113
const SolverStats & getStats() const
获取求解器统计信息
定义 UnarySolver.hpp:95
void setMaxIter(int maxIter)
设置最大迭代次数
定义 UnarySolver.hpp:92
double getAbsTol() const
获取绝对误差容限
定义 UnarySolver.hpp:83
std::enable_if<!std::is_base_of< UnaryScalarFunc, typenamestd::remove_pointer< Func >::type >::value, errc_t >::type solve(Func func, double min, double max, double &result)
求解一元方程(支持lambda函数)
定义 UnarySolver.hpp:105
double getRelTol() const
获取相对误差容限
定义 UnarySolver.hpp:81
double relTol_
相对误差容限
定义 UnarySolver.hpp:112
int getMaxIter() const
获取最大迭代次数
定义 UnarySolver.hpp:85
void setAbsTol(double absTol)
设置绝对误差容限
定义 UnarySolver.hpp:90
bool aIsClose(double a, double b, double relTol, double absTol)
判断两个数是否接近
定义 UnarySolver.cpp:27
求解器统计信息
定义 SolverStats.h:30