Question: Algorithm and Complexity, Python # Task 1a) Test the function with various angles and a's. The parameter should be positive but small. b). Find an
Algorithm and Complexity, Python
# Task 1a) Test the function with various angles and a's. The parameter should be positive but small.
b). Find an idea of how can we estimate the complexity of the above recursive routine. Can you improve its accuracy?
c). Build a similar algorithm for cosine and test its accuracy and complexity.
def cube(x):
return x*x*x
def p(x):
return 3*x - 4*cube(x)
def sine(angle, a):
if abs(angle)
return angle
else:
return p(sine(angle/3.0, a))
# Thel algorithm uses the identity sin(x) = 3*sin(x/3) - 4*sin(x/3)**3 # and the fact that for small arguments sin(x) is approximately equal to x. def cube (x): return x*x*x def p(x): return 3*x - 4* cube (x) def sine (angle, a): if abs (angle)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
