0

so I have coded this formula enter image description here

Which I get:

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

To explain a little bit this:
- Alpha: constant
- A0: constant
- AN : np.array([])(n values)
- theta: independent variable
After this, I need to calculate the next integral:enter image description here

Here is where Im having the problems:

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]

I have all the limits and everything. But I get the next error:

'float' object is not iterable

I dont know how to continue. So my question is: how can I integrate this function using the integrate.quad method? Maybe I shall change the way the sumatorie is made? How I can write the function in other way that this works? Thanks in advance

3
  • I have found an error in the 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], which should be : ch= integrate.quad(lambda theta:-(((alpha_char+A0)*tan(theta/2)+sumAN(theta,CoefAN,n_charl)))*(cos(theta)-cos(xa))*sin(theta),0,xa)[0] Commented Apr 15, 2020 at 16:32
  • 1
    There is a typo in your question I think it should be sin instead of sen in the first function. Commented Apr 15, 2020 at 16:45
  • Yeah, you are right. The first formula is a pic from my presentation and in Spain is quite common to call the sinus "sen" instead of "sin". Thanks anyways ;) ! Commented Apr 15, 2020 at 16:54

1 Answer 1

1

This should work

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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.