Python Forum
A program to define sine function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A program to define sine function
#3
I am a newbie to python and cannot understand most of your code, so whatever I didn't understand I have marked in bold. Kindly elaborate.
Thanks!

from itertools import count, islice
import math

def sine_terms(x):
t = x
f = -x ** 2
for n in count(3, 2):
yield t
t *= f /((n-1) * n)

def sine(x, n):
return sum(islice(sine_terms(x), n))

if __name__ == '__main__':
print(sine(6, 25), math.sin(6))
Reply


Messages In This Thread
A program to define sine function - by mohanp06 - Aug-17-2020, 06:19 PM
RE: A program to define sine function - by mohanp06 - Aug-19-2020, 07:07 AM
RE: A program to define sine function - by mohanp06 - Aug-25-2020, 06:16 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020