使用 scipy 输入向量的标量值函数的数值求积 [英] Numerical Quadrature of scalar valued function with vector input using scipy

查看:46
本文介绍了使用 scipy 输入向量的标量值函数的数值求积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用 scipy.integrate.quadrature 来集成一个标量值函数,该函数将固定维度的向量作为输入.然而,尽管 scipy.integrate.quadrature 声称它可以接受带有向量输入的函数,但我终生无法理解如何进行这项工作.

我可能误解了 scipy.integrate.quadrature 的文档,当它说函数可以接受向量输入时,它仅仅意味着它能够在多个点评估函数同时(这不等于我的问题).

更具体地说,我试图对函数 f(x) 进行积分,其中 x 是一个向量,f() 映射 x> 到一个标量.如果我对 scipy.integrate.quadrature 的初始解释是错误的,那么有谁知道任何可以计算积分的包(用 python 编写)我有提到吗?我知道有一种叫做 scipy.integrate.nquad 的东西,这也许就是我要找的东西?这里的任何指导或见解都会很棒.

解决方案

如果你的函数接受一个向量值的 x 作为输入,这意味着它的域是 n 维空间的某个子集.对于正交,这使它成为一个完全不同的野兽,这就是您遇到问题的原因.

您的集成领域是什么?3D 中的矩形?4D 球?棱镜?也许整个 nD 空间具有像 exp(-norm(x)^2) 这样的权重函数?(有关 3D 积分规则的图形表示,请参见下图.)根据此,有不同的积分规则.查看

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.

解决方案

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

这篇关于使用 scipy 输入向量的标量值函数的数值求积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆