-
Notifications
You must be signed in to change notification settings - Fork 0
/
ewarrick_triglib.py
54 lines (47 loc) · 1.18 KB
/
ewarrick_triglib.py
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
#make a sin, cos, tan library of trig functions
#using code from dgrin/inclass_hw3_2020/sinx_best_for_func.py
#collab: Nina Inman
import numpy as np
import math
#sine
def ewar_sin(x):
#take arg mod 2pi
x=x%(2.e0*np.pi)
#initialize iterator and sum
i = 0
s,sold = 0.e0,0.e0
#Keep at most 10000 terms in the Taylor series
for i in range(1000):
sold=s
s+= float((((-1)**i) * (x**((2*i) + 1))))/float(math.factorial(((2*i) + 1)))
#If converged to machine precision then break out of loop
if sold==s: break
return s
#cosine
def ewar_cos(x):
#take arg mod 2pi
x=x%(2.e0*np.pi)
#initialize iterator and sum
i = 0
c,cold = 0.e0,0.e0
#Keep at most 10000 terms in the Taylor series
for i in range(1000):
cold=c
c+= float((((-1)**i) * (x**((2*i)))))/float(math.factorial(((2*i))))
#If converged to machine precision then break out of loop
if cold==c: break
return c
#tangent
def ewar_tan(x):
#take arg mod 2pi
x=x%(2.e0*np.pi)
#initialize iterator and sum
i = 0
t,told = 0.e0,0.e0
#Keep at most 10000 terms in the Taylor series
for i in range(1000):
told=t
t+= (ewar_sin(x))/(ewar_cos(x))
#If converged to machine precision then break out of loop
if told==t: break
return t