Как я могу интегрировать эту функцию, используя библиотеку scipy.integrate? - PullRequest
0 голосов
/ 15 апреля 2020

поэтому я закодировал эту формулу enter image description here

Что я получаю:

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 значений)
- тета: независимая переменная
После этого мне нужно вычислить следующий интеграл: enter image description here

Вот где у меня проблемы:

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]

У меня есть все ограничения и все. Но я получаю следующую ошибку:

объект 'float' не повторяется

Я не знаю, как продолжить. Итак, мой вопрос: как я могу интегрировать эту функцию, используя метод integrate.quad? Может быть, я изменю способ изготовления суматора ie? Как я могу написать функцию другим способом, чтобы это работало? Заранее спасибо

1 Ответ

1 голос
/ 15 апреля 2020

Это должно работать

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))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...