[英]How can I integrate the Ordinary differential equation using odeint from scipy.integrate?
[英]How can I integrate this function using the scipy.integrate library?
我得到:
def sumAN(theta,CoefAN,n_cl):
# this function give us the sumatory in the right side of the formula
Sumatorio = np.array([])
for count,i in enumerate(theta):
sumatorio = 0
for count2,j in enumerate(n_cl):
sumatorio = sumatorio +CoefAN[count2]*sin(int(count2+1)*i)
Sumatorio = np.append(Sumatorio,sumatorio)
return Sumatorio
cl= 4*((np.radians(alpha)+A0)*tan(theta/2)+sumAN(theta,CoefAN,n_cl))
稍微解釋一下:
- 阿爾法:恆定
- A0:常數
- AN:np.array([])(n 個值)
- theta:自變量
在此之后,我需要計算下一個積分:
這是我遇到問題的地方:
ch = integrate.quad(lambda theta:(4*((alpha_char+A0)*tan(theta/2)+sumAN(theta,CoefAN,n_charl)))*(cos(theta)-cos(xa))*sin(theta),0,xa)[0]
我有所有的限制和一切。 但我得到下一個錯誤:
'浮動' object 不可迭代
我不知道如何繼續。 所以我的問題是:如何使用integrate.quad 方法集成這個function? 也許我會改變總結的方式? 我如何以其他方式編寫 function? 提前致謝
這應該有效
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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.