1

I have a function which defines an integral.

An array A[i,j] is later defined by multiplying said function by 0.5/pi.

I get the error:

TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'

Clearly this is because I am multiplying something of no type by a number, which python cannot interpret.

What would you all suggest is the easiest fix to this error?

I have included my code below (does not include all code, so sum variables might seem undefined)

def integral_normal(p_i, p_j):
"""Evaluates the contribution of a panel at the center-point of another,
in the normal direction.

Arguments
---------
p_i -- panel on which the contribution is calculated.
p_j -- panel from which the contribution is calculated.

Returns
-------
Integral over the panel of the influence at a control-point.
"""
def func(s):
    return ( (+(p_i.xc-(p_j.xa-sin(p_j.beta)*s))*cos(p_i.beta)
              +(p_i.yc-(p_j.ya+cos(p_j.beta)*s))*sin(p_i.beta))
            /((p_i.xc-(p_j.xa-sin(p_j.beta)*s))**2
              +(p_i.yc-(p_j.ya+cos(p_j.beta)*s))**2) )
    return integrate.quad(lambda s:func(s), 0., p_j.length)[0]

# computes the source influence matrix
A = np.empty((N_panels, N_panels), dtype=float)
np.fill_diagonal(A, 0.5)

# use enumerate to access element panels individually from 0 to i, locates element of A to fill.
for i, p_i in enumerate(panels):
    for j, p_j in enumerate(panels):
        if i != j:
            A[i,j] = 0.5/pi*integral_normal(p_i, p_j)

# computes right hand side of linear system
b = - u_inf * np.cos([p.beta for p in panels])

# solves the linear system
sigma = np.linalg.solve(A, b)

for i, panel in enumerate(panels):
    panel.sigma = sigma[i]

Here is the error:

TypeError                                 Traceback (most recent call last)
<ipython-input-101-b5c8b9263c2d> in <module>()
      26     for j, p_j in enumerate(panels):
      27         if i != j:
----> 28             A[i,j] = 0.5/pi*integral_normal(p_i, p_j)
      29 
      30 # computes right hand side of linear system

TypeError: unsupported operand type(s) for *: 'float' and 'NoneType'
Doug Fox
  • 23
  • 1
  • 1
  • 6
  • Your `func(s)` function looks a little unusual. Did you know, a `return` statement will cause a function to end immediately, and no statements appearing after it will run? So even though `func(s)` has two lines, only the first will ever be reached. – Kevin Nov 24 '14 at 20:35
  • Does your function `integral_normal(p_i, p_j)` return anything? – xbb Nov 24 '14 at 20:41
  • Can you edit in the rest of your whitespace? Since whitespace is significant in Python, it's unclear if and when your `integral_normal()` function ends. – bjornsen Nov 24 '14 at 20:47

1 Answers1

0

Assuming this is the entire definition of integral_normal(), you are never actually returning a value from the function. By default, if you do not have a return statement, python will return None, meaning your recursive call to integral_normal(p_i, p_j) on line 28 will always return None. That's a lot of words to say "You need to actually return a value."

bjornsen
  • 604
  • 1
  • 4
  • 14
  • Thank you! The error was because of my indentation for the return on the integral_normal function. Cheers! – Doug Fox Nov 24 '14 at 20:49