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

use python and please explain your steps 1. Consider the integration r1 cos(3cos

ID: 3168183 • Letter: U

Question


use python and please explain your steps

1. Consider the integration r1 cos(3cos (x)) dx J-1 Find the above integral using the Numpy module for trapezoidal rule. Start with 2 panels, find the integral and store its value. Next, increase the number of panels by 2 and compare the new result with the older result and store the difference. Keep increasing the number of panels by 2 and storing the difference between the present and older result. Stop increasing panels when you find that the a. ore you stopped

Explanation / Answer

import numpy as np

def func(x):
return np.cos(3*np.arccos(x))

results = list()
n = 2
x = np.linspace(-1,1,n) # will slice the range from -1 to 1 into n parts
res = np.trapz(func(x))
results.append(res)

while True:
n += 2
x = np.linspace(-1,1,n)
res = np.trapz(func(x))
results.append(res)
# if the difference between two consecutive results is < 1e-6,
# no need to move further
if abs(results[-1] - results[-2]) < 1e-6:
break

print('Result:', results[-1])
print('Panels:', n)