Program to Find the value of cos ( nÃƒÆ ’ Ã † â €™ Ãƒâ € Ã ¢ â ‚¬ â „¢ ÃƒÆ ’ Ã ¢ â ‚¬¦½ ÃƒÆ ’ Ã † â €™ Ãƒ ¢ Ã ¢ â € š ¬¹ ÃƒÆ ’ Ã ¢ â ‚¬¦ Ãƒ ¢ Ã ¢ â € š ¬ Ã … â € œ ) | ''Python3 program to find the value of cos(n-theta) ; ''Function to calculate the binomial coefficient upto 15 ; '' use simple DP to find coefficient ; ''Function to find the value of cos(n-theta) ; ''find sinTheta from cosTheta ; '' to store the required answer ; '' use to toggle sign in sequence. ; ''Driver code
import math NEW_LINE MAX = 16 NEW_LINE nCr = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ] NEW_LINE def binomial ( ) : NEW_LINE INDENT for i in range ( MAX ) : NEW_LINE for j in range ( 0 , i + 1 ) : NEW_LINE if j == 0 or j == i : NEW_LINE DEDENT nCr [ i ] [ j ] = 1 NEW_LINE INDENT else : NEW_LINE nCr [ i ] [ j ] = nCr [ i - 1 ] [ j ] + nCr [ i - 1 ] [ j - 1 ] NEW_LINE DEDENT def findCosnTheta ( cosTheta , n ) : NEW_LINE INDENT sinTheta = math . sqrt ( 1 - cosTheta * cosTheta ) NEW_LINE ans = 0 NEW_LINE DEDENT toggle = 1 NEW_LINE for i in range ( 0 , n + 1 , 2 ) : NEW_LINE INDENT ans = ans + nCr [ n ] [ i ] * ( cosTheta ** ( n - i ) ) * ( sinTheta ** i ) * toggle NEW_LINE toggle = toggle * - 1 NEW_LINE DEDENT return ans NEW_LINE if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT binomial ( ) NEW_LINE cosTheta = 0.5 NEW_LINE n = 10 NEW_LINE print ( findCosnTheta ( cosTheta , n ) ) NEW_LINE DEDENT