Taylor series expansion to derive cos angle values

241 views Asked by At

Deriving values of trigonometric angles by Taylor series expansion is one of the most useful methods. For trigonometric angles we have to convert angle in degree to radians. First 2 to 3 expansion of Taylor polynomials gives accurate values almost to 4 digits. But if we require higher degree of accuracy with more accurate decimal places, I found some difficulty with Taylor series expansion.

For example for deriving cos(4Pi/15) or cos80(degrees) by Python programming, I have tried as follows

#Taylor series Cosine value for cos 80^^
import time
import math
from decimal import*
getcontext().prec = 100
b = 3.141592653589793238462643383279
print(b)

a = 80 # float(input("Enter required angle to calculate cos value: \n"))

#Calculate angle in radians

R = b*a/180
print("Angle in radians is: ",Decimal(R))
#r = math.radians(a)
#print(r)
#Taylor expansion

c = int(input("Enter number of terms to expand cos angle: \n"))
begin = time.time()
V = 0
for i in range(c):
    coef = (-1)**i
    num = Decimal(R)**(2*i)
    denom = math.factorial(2*i)
    V = V + (coef)*((num)/(denom))
print(V)
end = time.time()
print("Time for execution is \n", end - begin)
#Prints accurate to 16 digits
#print(math.sqrt(1)/2)

n = int(input("Enter a positive integer to get number of cycles to caluculate cos80\n "))
x = Decimal(2).sqrt()
begin = time.time()
for i in range(n):
    x = Decimal(2 + x).sqrt()
    x = Decimal(2 + x).sqrt()
    x = Decimal(2 - x).sqrt()

print(x/2)
end = time.time()
print("Time for execution is \n", end - begin)

I have manually given 30 decimal accuracy of Pi to calculate radians in Taylor series expansion

But another method - finite cycles of infinite nested square roots of 2 gives better results compared to Taylor series expansion (I have compared with Wolfram alpha.

This fallacy happens with Taylor series expansion because expansion of Taylor polynomial involves powers and factorials. Is it the reason for inaccurate values in decimals?

What are the other methods used to get the results of such angles to many digits accurate?

What are the methods used by Wolfram alpha? (i.e. methods other than Taylor series expansion)

0

There are 0 answers