26 std::function<double(size_t, double)>
_fn;
29 inline static std::vector<double>
cache;
43 inline double sum(
double x)
const {
45 for (
size_t idx = 0; idx <= _n + 1; idx++) {
59 const size_t cachesize = 11;
64 for (
size_t idx = 1; idx < cachesize; idx++) {
69 if (n < cache.size()) {
81 static inline int sign(
size_t n) {
return n % 2 == 0 ? 1 : -1; }
109 _fn = [
this](
size_t np,
double x) {
return term(np, x); };
118 double term(
size_t n,
double x) {
119 _powterm = n == 0 ? 1 : _powterm *= x;
139 _fn = [
this](
size_t np,
double x) {
return term(np, x); };
148 double term(
size_t n,
double x) {
149 size_t npow = 2 * n + 1;
150 _powterm = n == 0 ? x : (_powterm *= x * x);
170 _fn = [
this](
size_t np,
double x) {
return term(np, x); };
179 double term(
size_t n,
double x) {
181 _powterm = n == 0 ? 1 : (_powterm *= x * x);
191 const size_t nmax = 10;
193 const Exp myexp(nmax);
194 const Sin mysin(nmax);
195 const Cos mycos(nmax);
200 std::cout << std::setprecision(7) << std::scientific;
201 std::cout <<
"N=" << nmax << std::endl;
202 std::cout <<
"x0=" << x0 << std::endl;
203 std::cout << myexp(x0) <<
"\t" << std::exp(x0) << std::endl;
204 std::cout << mysin(x0) <<
"\t" << std::sin(x0) << std::endl;
205 std::cout << mycos(x0) <<
"\t" << std::cos(x0) << std::endl;
void ex1()
run_power_series Berechnung von Näherungswerten für e^x, sin(x), cos(x) 10 Terme
The Cos class Taylorpolynom für cos(x)
The Exp class Taylorpolynom für e^x.
Sin(size_t n)
Sin Konstruktor.
Exp(size_t n)
Exp Konstruktor.
static constexpr double E
double sum(double x) const
sum Summe aller Terme
PowerSeries(size_t n)
PowerSeries Konstruktor.
The PowerSeries class Basisklasse Berechnung von Taylorpolynomen von Funktionen.
static int sign(size_t n)
sign
double term(size_t n, double x)
term Term des Taylor-Polynoms
std::function< double(size_t, double)> _fn
Cos(size_t n)
Cos Konstruktor.
static std::vector< double > cache
double term(size_t n, double x)
term Term des Taylor-Polynoms
double term(size_t n, double x)
term Term des Taylor-Polynoms
static constexpr double PI
The Sin class Taylorpolynom für sin(x)
double operator()(double x) const
operator ()
static double factorial(size_t n)
factorial Fakultät