15 template<
size_t N = 10>
20 inline static std::array<double, N> _data;
22 inline static bool _init =
false;
26 inline static void init() {
29 for (
size_t idx = 1; idx <
N; idx++) {
30 _data[idx] = idx * _data[idx - 1];
42 inline static double get(
size_t n) {
43 return n <
N ? _data[n] : (n *
get(n - 1));
52 template<
class T =
double,
size_t N = 15>
61 mutable double xval = 1;
79 inline double term(
double x,
size_t n)
const {
80 return static_cast<const T *
>(
this)->term(x, n);
88 inline double sum(
double x)
const {
91 for (
size_t idx = 0; idx < _n + 1; idx++) {
102 inline int sign(
size_t n)
const {
return n % 2 == 0 ? 1 : -1; }
127 inline double term(
double x,
size_t n)
const {
128 xval *= n == 0 ? 1 : x;
155 inline double term(
double x,
size_t n)
const {
156 const size_t npw = 2 * n + 1;
157 xval *= n == 0 ? x : (x * x);
184 inline double term(
double x,
size_t n)
const {
185 const size_t npw = 2 * n;
186 xval *= n == 0 ? 1 : (x * x);
207 const double x0 = 0.2;
208 std::cout << myexp(x0) << std::setw(10) << std::exp(x0) << std::endl;
209 std::cout << mysin(x0) << std::setw(10) << std::sin(x0) << std::endl;
210 std::cout << mycos(x0) << std::setw(10) << std::cos(x0) << std::endl;
217 using namespace std::chrono;
218 constexpr
size_t N = 3;
223 const double x0 = 0.2;
225 double y1 = 0.0, y2 = 0.0, y3 = 0.0, y4 = 0.0, y5 = 0.0, y6 = 0.0;
227 auto start1 = steady_clock::now();
228 for (
double idx = 0; idx < 100000; idx++) {
233 auto end1 = steady_clock::now();
234 auto diff1 = duration<double, std::milli>(end1 - start1).count();
236 auto start2 = steady_clock::now();
237 for (
double idx = 0; idx < 100000; idx++) {
242 auto end2 = steady_clock::now();
243 auto diff2 = duration<double, std::milli>(end2 - start2).count();
245 std::cout << std::setprecision(4) << std::scientific;
247 std::cout <<
"dt1=" << diff1 <<
" ms" << std::endl;
248 std::cout <<
"dt2=" << diff2 <<
" ms" << std::endl;
249 std::cout <<
"dt1/dt2=" << diff1 / diff2 << std::endl;
250 std::cout <<
"---------------------------------" << std::endl;
252 std::cout <<
"exp(x)" << std::setw(w) <<
"sin(x)" << std::setw(w) <<
"cos(x)" << std::endl;
253 std::cout << y1 << std::setw(w) << y2 << std::setw(w) << y3 << std::endl;
254 std::cout << y4 << std::setw(w) << y5 << std::setw(w) << y6 << std::endl;
The Cos class Die Funktion cos(x) als Taylor-Polynom.
double term(double x, size_t n) const
term allgemeiner Term (Funktionsspezifisch)
The Exp class Die Funktion e^x als Taylor-Polynom.
The Factorial class Berechnung von Fakultäten.
double term(double x, size_t n) const
term Term des Taylor-Polynoms
The PowerSeries class Schnittstelle zur Entwicklung von Funktionen in Potenzreihen Parameter...
Exp(size_t n)
Exp Konstruktor.
Factorial< 15 > Factorial
double term(double x, size_t n) const
term Term des Taylor-Polynoms
double term(double x, size_t n) const
term Term des Taylor-Polynoms
Cos(size_t n)
Cos Konstruktor.
double sum(double x) const
sum Partialsumme ...
void ex1()
run_power_series Beispielanwendung
PowerSeries(size_t n)
PowerSeries.
Sin(size_t n)
Sin Konstruktor.
static double get(size_t n)
The Sin class Die Funktion sin(x) als Taylor-Polynom.
int sign(size_t n) const
sign Berechne (-1)^n
Factorial & operator=(const Factorial &)=delete
double operator()(double x) const
operator () berechne Funktionswert