Question: import math import stdio import sys # Return sin(x) calculated using the formula: # sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ...

 import math import stdio import sys # Return sin(x) calculated using

import math import stdio import sys

# Return sin(x) calculated using the formula: # sin(x) = x - x^3/3! + x^5/5! - x^7/7! + ... def sin(x): # Initialize total (sum of the series) to 0.0. ...

# Initialize term (each term in the series) to 1.0, and sign (sign of # the term) to 1. ...

# Initialize i (loop variable) to 1. ...

# Repeat until convergence. while ...: # Set term to its previous value times x divided by i. ...

# If i is odd, increment total by sign * term, and toggle # (negate) sign. ...

# Increment i. ...

# Return the result. ...

# Test client [DO NOT EDIT]. Reads a float x (representing an angle in # degrees) from the command line and prints sin(x) and math.sin(x). def _main(): x = math.radians(float(sys.argv[1])) stdio.writeln(sin(x)) stdio.writeln(math.sin(x))

if __name__ == '__main__': _main()

Please keep it as it is imported no changed

Problem 1. (Sine Function) Implement the function sin() in sin.py that calculates the sine of the argument x in radians, using the formula: Hint: In order to avoid the inaccuracies caused by computing with huge numbers, follow the approach described on page 97 of the IPP text for computing the function e $ python3 sin.py 60 0.8660254037844385 0.8660254037844386

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!