-
Notifications
You must be signed in to change notification settings - Fork 0
/
trig.py
53 lines (45 loc) · 1.01 KB
/
trig.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
# -*- coding: utf-8 -*-
"""
Created on Mon Feb 3 12:54:30 2020
@author: shaun
"""
import numpy as np
import math
def ssin(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 scos(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)))))/float(math.factorial(((2*i))))
#If converged to machine precision then break out of loop
if sold==s: break
return s
def stan(x):
result=sin(x)/cos(x)
return result
def ssec(x):
result=1/cos(x)
return result
def scosec(x):
result=1/sin(x)
return result
def scotan(x):
result=1/tan(x)
return result