-
Notifications
You must be signed in to change notification settings - Fork 0
/
frosttriglib.py
66 lines (47 loc) · 1.31 KB
/
frosttriglib.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
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# coding: utf-8
# In[3]:
import numpy as np
import math
def fsin(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(10000):
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
def fcos(x):
#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(10000):
sold=s
s+= float((((-1)**i) * (x**((2*i) ))))/float(math.factorial(((2*i) )))
#If converged to machine precision then break out of loop
if sold==s: break
return s
#Tangent is just sine/cosine, so call those two functions
def ftan(x):
s = fsin(x)/fcos(x)
return s
#Call in cosine function since secant is 1/cosine
def fsec(x):
s = 1/fcos(x)
return s
#Call sine function since cosecant is 1/sine
def fcsc(x):
s=1/fsin(x)
return s
#Contangent is cosine over sine, so we just call those above functions
def fcot(x):
s=fcos(x)/fsin(x)
return s
# In[6]:
# In[ ]: