1 回答

TA贡献1830条经验 获得超3个赞
这应该工作
import numpy as np
from scipy.integrate import quad
def integrand(theta, theta_a, alpha, A):
sum = 0
# get sum
for index, value in enumerate(A):
if index == 0:
sum += (alpha + A[index]) * np.tan(0.5 * theta)
else:
sum += A[index] * np.sin(index * theta)
# note that multiplication with 4 and multiplication with 1/4
# result in one as prefactor
return -sum * (np.cos(theta) - np.cos(theta_a))
# calculate integral
theta_a = 0
alpha = 0
array_coefficients = np.array([1, 2, 3, 4])
integral = quad(integrand, 0, 1, args=(theta_a , alpha, array_coefficients))
添加回答
举报