Compute the fourth order Taylor expansion for sin(x) and cos(x) and sin(x)cos(x) around 0. (30%) a. Write down your manual calculation AND Python script to answer above’s question b. Which produces less error for x-1/2: computing the Taylor expansion for sin and cos separately then multiplying the result together, or computing the Taylor expansion for the product first then plugging in x? C. Use the same order of Taylor series to approximate cos (1/4) and determine the truncation error bound. You may include either your manual calculation OR Python script for this question

Question

Compute the fourth order Taylor expansion for sin(x) and cos(x) and sin(x)cos(x) around 0. (30%) a. Write down your manual calculation AND Python script to answer above’s question b. Which produces less error for x-1/2: computing the Taylor expansion for sin and cos separately then multiplying the result together, or computing the Taylor expansion for the product first then plugging in x? C. Use the same order of Taylor series to approximate cos (1/4) and determine the truncation error bound. You may include either your manual calculation OR Python script for this question

Answer

a. The fourth order Taylor expansion for sin(x) around 0 is

The fourth order Taylor expansion for cos(x) around 0 is:

The fourth order Taylor expansion for sin(x)cos(x) around 0 is:

Explanation:

To write a Python script to compute these expansions, we can define functions for each term in the expansions and add them up:

import math

def cos_term(x, n):

def sin_cos_term(x, n):

if n == 0:

return x

elif n == 1:

return -x**3 / 3

elif n == 2:

return 2*x**5 / 15

elif n == 3:

return -2*x**7 / 315

elif n == 4:

return 2*x**9 / 2835

def sin_taylor(x, order):

result = 0

for n in range(order+1):

result += sin_term(x, n)

return result

def cos_taylor(x, order):

result = 0

for n in range(order+1):

result += cos_term(x, n)

return result

def sin_cos_taylor(x, order):

result = 0

for n in range(order+1):

result += sin_cos_term(x, n)

return result

# Example usage:

x = math.pi/2

print(“sin(pi/2) =”, sin_taylor(x, 4))

print(“cos(pi/2) =”, cos_taylor(x, 4))

print(“sin(pi/2)cos(pi/2) =”, sin_cos_taylor(x, 4))

b. Computing the Taylor expansion for sin and cos separately then multiplying the result together produces less error for x=π/2. This is because the Taylor expansion for sin and cos separately has alternating signs for each term, which helps to cancel out some of the error. On the other hand, the Taylor expansion for the product has terms with the same sign, which can amplify the error.

c. The fourth order Taylor expansion for cos(x) around 0 is:

To approximate cos(π/4), we plug in x=π/4 into the expansion:

The truncation error bound for the fourth order Taylor series is given by:

Compute the fourth order Taylor expansion for sin(x) and cos(x) and sin(x)cos(x) around 0. (30%) a. Write down your manual calculation AND Python script to answer above's question b. Which produces less error for x-1/2: computing the Taylor expansion for sin and cos separately then multiplying the result together, or computing the Taylor expansion for the product first then plugging in x? C. Use the same order of Taylor series to approximate cos (1/4) and determine the truncation error bound. You may include either your manual calculation OR Python script for this question

Therefore, the approximation of cos(π/4) using the fourth order Taylor series has an error of at most 0.0000036.

Leave a Comment