亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 scipy.integrate 庫集成此功能?

如何使用 scipy.integrate 庫集成此功能?

狐的傳說 2022-10-11 10:15:53
所以我編寫了這個公式我得到: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 Sumatoriocl= 4*((np.radians(alpha)+A0)*tan(theta/2)+sumAN(theta,CoefAN,n_cl))稍微解釋一下:- Alpha:常量- 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]我有所有的限制和一切。但我得到下一個錯誤:“浮動”對象不可迭代我不知道如何繼續。所以我的問題是:如何使用integrate.quad 方法集成這個函數?也許我會改變總結的方式?我如何以其他方式編寫函數?提前致謝
查看完整描述

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))


查看完整回答
反對 回復 2022-10-11
  • 1 回答
  • 0 關注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號