Programming Pandit

c/c++/c#/Javav/Python


Latest Update

Monday, November 23, 2020

Python program to function sin(x,n) to calculate the value of sin(x) using its taylor series expansion up to n terms. by G Krishna Chauhan

Source Code


 

import math 

def fact(k): 

    if k<=1:

         return 1 

    else: 

        return k*fact(k-1) 

step=int(input("How many terms : "))

x=int(input("Enter the value of x :")) 

sum=0 

for i in range(step+1): 

    sum+=(math.pow(-1,i)*math.pow(x,2*i+1))/fact(2*i+1)

 print("The result of sin",'(', x, ')', "is :", sum)



OUTPUT


How many terms : 2

Enter the value of x :1

The result of sin ( 1 ) is : 0.8416666666666667 

No comments:

Post a Comment