forked from SheenamYadav/mca101_vidul
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysin.py
31 lines (25 loc) · 770 Bytes
/
mysin.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
def mysin(x):
'''
objective : to compute value of mathematical function sin
approach : using infinite series of sin i.e.
x - x**3/3! + x**5 /5! - . . . ....
and appling by use of while loop
termination condition ;
when absolute term is less than e
return value; sin : calculated sin value
'''
print('execution started')
term = x
e = 0.0000000000000001
n = 1
sin = 0
flag = False
while flag != True:
pterm = term
sin = sin + term
term = -((term * (x * x))/((2*n)*(2*n+1)))
n = n + 1
diff = term - pterm
if abs(diff) < e :
flag = True
return sin