Numerical Quadrature of scalar valued function with vector input using scipy
Asked Answered
M

1

0

I have been trying to use scipy.integrate.quadrature for integrating a scalar-valued function that takes as input a vector of fixed dimension. However, despite the claim of scipy.integrate.quadrature that it can take functions with vector inputs, I cannot for the life of me understand how to make this work.

It is possible that I am misunderstanding the documentation for scipy.integrate.quadrature and that when it says the function can take vector inputs it simply means that it is able to evaluate the function at multiple points simultaneously (which is not equivalent to my problem).

More specifically I am trying to integrate over a function, f(x), where x is a vector and f() maps x to a scalar. If its true that my initial interpretation of scipy.integrate.quadrature is false, does anyone know of any packages (written in python) that can compute an integral in the way that I have mentioned ? I know there is something called scipy.integrate.nquad which perhaps is what I'm looking for? Any guidance or insight here would be awesome.

Mestizo answered 26/2, 2019 at 20:10 Comment(1)
"... when it says the function can take vector inputs it simply means that it is able to evaluate the function at multiple points simultaneously ..." Yes, that is what it means. "I know there is something called scipy.integrate.nquad which perhaps is what I'm looking for?" Yes, it is. Take a look at the examples in the nquad docstring. There are also dblquad and tplquad for the special cases where x is 2-d or 3-d, respectively.Voight
O
0

If your function takes a vector-valued x as input, it means its domain some subset of the n-dimensional space. For quadrature, that makes it an entirely different beast which is why you're having problems.

What's your domain of integration? A rectangle in 3D? A ball in 4D? A prism? Perhaps the entire nD space with a weight function like exp(-norm(x)^2)? (See picture below for an graphical representation of integration rule in 3D.) Depending on that, there are different integration rules. Check out quadpy (a Python package of mine).

enter image description here

Ordeal answered 7/3, 2019 at 10:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.