0

I usually use scipy to do integration by python. This is my code,

from scipy import integrate
    def f(x, y, z):`
        return [x**2 + y**2 +3*z, x + y]
a = integrate.quad(f, 0, 1, (2,2))
print(a)

I want to do the same integration to both of the elements simultaneously, something like map. After I executed it, it shows:

quadpack.error: Supplied function does not return a valid float.

Amin Etesamian
  • 3,363
  • 5
  • 27
  • 50
jiangniao
  • 125
  • 1
  • 2
  • 11
  • 1
    To get answers here on SO you should show us code you have written that attempts to solve the problem you want to solve. Then ask specific questions about difficulties you have encountered when you tried to execute that code. – Bill Bell Mar 01 '17 at 18:04

1 Answers1

0

You f returns a list of 2 numbers:

In [122]: def f(x, y, z):
     ...:      return [x**2 + y**2 +3*z, x + y]
     ...: 
In [123]: f(0,2,2)
Out[123]: [10, 2]
In [124]: f(1,2,2)
Out[124]: [11, 3]

quad wants you to give it one float.

You'll have to iterate or other wise solve the functions separately. Or come up with your own quad equivalent. There's nothing terribly fancy about this kind of integration.

For more on this see (duplicate?)

Integrating functions that return an array in Python

Community
  • 1
  • 1
hpaulj
  • 221,503
  • 14
  • 230
  • 353