This commit is contained in:
david 2019-05-06 14:27:39 +02:00
commit 7750dbddb1
2 changed files with 38 additions and 0 deletions

BIN
taylor Executable file

Binary file not shown.

38
taylor.cpp Normal file
View File

@ -0,0 +1,38 @@
#include<iostream>
#include<math.h>
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;
}