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
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)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.