LMCAS
Lamina Computer Algebra System
载入中...
搜索中...
未找到
mixed_transcendental_deduplication.cpp
浏览该文件的文档.
2#include <algorithm>
3#include <cmath>
4
5namespace LMCAS {
6
7std::vector<lmmc_real_t> deduplicate_roots(
8 std::vector<NumericRoot>& roots,
9 lmmc_real_t tolerance,
10 int max_roots)
11{
12 if (roots.empty()) {
13 return {};
14 }
15
16 std::sort(roots.begin(), roots.end(),
17 [](const NumericRoot& a, const NumericRoot& b) {
18 return a.value < b.value;
19 });
20 lmmc_real_t threshold = 10.0 * tolerance;
21 std::vector<NumericRoot> survivors;
22 survivors.reserve(roots.size());
23 survivors.push_back(roots[0]);
24
25 for (size_t i = 1; i < roots.size(); ++i) {
26 NumericRoot& last = survivors.back();
27 if (std::fabs(roots[i].value - last.value) < threshold) {
28 if (roots[i].residual < last.residual) {
29 last = roots[i];
30 }
31 } else {
32 survivors.push_back(roots[i]);
33 }
34 }
35 std::vector<lmmc_real_t> result;
36 result.reserve(survivors.size());
37 for (const auto& r : survivors) {
38 result.push_back(r.value);
39 }
40
41 if (max_roots > 0 && result.size() > static_cast<std::size_t>(max_roots)) {
42 result.resize(static_cast<size_t>(max_roots));
43 }
44
45 return result;
46}
47
48}
__attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_exp_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexSymbolicResult complex_trig_form_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_nth_root_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std __attribute__((visibility("default"))) ComplexRootsResult solve_complex_quadratic_checked(std std::shared_ptr< SymbolicExpr > r
std::vector< lmmc_real_t > deduplicate_roots(std::vector< NumericRoot > &roots, lmmc_real_t tolerance, int max_roots)
const MultiPoly & b
__attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) VectorCalculusExprResult curve_integral_scalar_checked(const std __attribute__((visibility("default"))) std const VectorField const std::string const std::shared_ptr< SymbolicExpr > & a
ExprSetResult roots(const ExprPtr &expression, const std::string &variable, ComputationContext &context, const SolveOptions &options)
const std::string const ExprPtr & value
lmmc_real_t value
根的数值
lmmc_real_t residual
残差(将根代入方程后的绝对值)
数值根结果,包含根值,残差和迭代次数.
混合超越方程求解:符号预处理 + 自适应根隔离 + Newton-Raphson 精化.