Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with these 2 functions for python 3.x. Will post my current code and

ID: 3606356 • Letter: I

Question

I need help with these 2 functions for python 3.x. Will post my current code and what the function is supposed to do below.

Function 1

def mycos_mod(x, tol=1e-8):
"""
compute cos(x) by summing taylor expansion at x0=j*pi, (for some integer j such that
j*pi is closest to x), if j is even, then
cos(x) = 1 + (x-x0)^4/4! + (x-x0)^8/8! + (x-x0)^12/12! + (x-x0)^16/16! + ...
- (x-x0)^2/2! + (x-x0)^6/6! + (x-x0)^10/10! + ... )
if j is odd, multiply the above by -1.
"""
#if you can, apply the more efficient 'updating' method instead of direct sum term-by-term

Function 2

def mysin_mod(x, tol=1e-8):
"""
compute sin(x) by summing taylor expansion at x0=j*pi, (for some integer j such that
j*pi is closest to x), if j is even, then
sin(x) = (x-x0) - (x-x0)^3/3! + (x-x0)^5/5! +.... + (-1)^k*(x-x0)^(2k+1)/(2k+1)! + ...
if n is odd, multiply the above by -1.
"""

If you can help me figure these out thatd be very helpful thanks.

Explanation / Answer

import math def getJ(x): # To get the value of j closest = 0.0 newJ = 0 for j in range(0, x, 1): if closest tol: # If error is more than acceptable value # calculating sin(x) sinx += math.pow(-1, term) * math.pow((x - x0), (2 * term + 1)) / factorial(2 * term + 1) term += 1 # Return sin(x) depending on value of j if j % 2 == 0: return sinx else: return -1.0 * sinx