You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
812 B
28 lines
812 B
#pragma once
|
|
|
|
#include "GL_integrator.hpp"
|
|
#include "TS_integrator.hpp"
|
|
|
|
// 高斯-勒让德一维积分:积分区间 [a, b]
|
|
template<typename Func>
|
|
double gauss_integrate_1D(double a, double b, Func&& func, int q) {
|
|
double sum = 0.0;
|
|
for (int i = 0; i < q; ++i) {
|
|
double x = GLIntegrator<double>::x(q, i, a, b);
|
|
double w = GLIntegrator<double>::w(q, i, a, b);
|
|
sum += w * func(x);
|
|
}
|
|
return sum;
|
|
}
|
|
|
|
// tanh-sinh 一维积分:积分区间 [a, b]
|
|
template<typename Func>
|
|
double tanh_sinh_integrate_1D(double a, double b, Func&& func, int q) {
|
|
double result = 0.0;
|
|
for (int i = 0; i < q; ++i) {
|
|
double x = TSIntegrator<double>::x(q, i, a, b);
|
|
double w = TSIntegrator<double>::w(q, i, a, b);
|
|
result += w * func(x);
|
|
}
|
|
return result;
|
|
}
|