-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaylorSeries.cpp
More file actions
71 lines (56 loc) · 1010 Bytes
/
TaylorSeries.cpp
File metadata and controls
71 lines (56 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
typedef long double ld;
#define MAXN 100
ull fn[MAXN];
ull fact(ull n)
{
if( fn[n] == 0 )
{
if( n < 2 )
{
fn[n] = 1;
}else
{
fn[n] = fn[n-1] + fn[n-2];
}
}
return fn[n];
}
ld sine(ld x, size_t precision)
{
ld ans = 0;
int sign = -1;
int den = idx = 1;
ld p = x*x;
for(int i=1; i <= presicion; ++i)
{
sign *= -1;
ans += sign * x / den;
den *= ++idx * ++idx;
x *= p;
}
return ans;
}
ld cosine(ld x, size_t precision)
{
ld ans = 0;
int sign = 1;
int den = 1, idx = 0;
ld p = x*x;
x *= x;
for(int i=1; i<=presicion; ++i)
{
sign *= -1;
ans += sign * x / den;
den *= ++idx * ++idx;
x *= p;
}
return 1 + ans;
}
int main()
{
return 0;
}