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 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.8660254037844386Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started