commit 7750dbddb15ba21ff609c3252a2cae41eb96a10a Author: david Date: Mon May 6 14:27:39 2019 +0200 Taylor diff --git a/taylor b/taylor new file mode 100755 index 0000000..12b975b Binary files /dev/null and b/taylor differ diff --git a/taylor.cpp b/taylor.cpp new file mode 100644 index 0000000..6d8d6fb --- /dev/null +++ b/taylor.cpp @@ -0,0 +1,38 @@ +#include +#include + +using namespace std; + +long factorial(long N) { + if (N < 2) return 1; + for (int i = N - 1; i > 0; --i) { + N = N * i; + } + return N; +} + +double sin_taylor(double x, int N) { + double res = 0; + for (int k = 0; k < N; ++k) { + res += pow(-1, k) * pow(x, 1 + 2*k) / (double)factorial(1 + 2*k); + } + return res; +} +void find_interval(int N) { + for (double x = 0; x < 3.14; x += 0.00000001) { + double real = sin(x); + double taylor = sin_taylor(x, N); + //cout << "Real: " << real << " Taylor: " << taylor << endl; + if (abs(real - taylor) > 0.001) { + cout << "Interval: [0, " << x - 0.01 << "]" << endl; + break; + } + } +} + +int main(int argc, char* argv[]) { + find_interval(1); + find_interval(2); + find_interval(3); + return 0; +}