使用 scipy/python 和 mathematica 进行第三类完全积分

问题描述 投票:0回答:1

我最近遇到一个问题,需要使用第三类完全椭圆积分。它被写成 PI(m,n) 形式的单个函数。老实说,我对这个主题并不熟悉,我需要的只是计算这个值。我在网上搜索了一下,对于 python 有两个可用的包:scipy 和 mpmath。 这两个包的计算语句是不同的:对于 mpmath (ellippi),它只是“第三类完全椭圆积分”,而对于 scipy (elliprj),它是“第三类对称椭圆积分”。这两个声明已经让我加倍了。我首先尝试了 mpmath,不知何故它产生了复数。之后我尝试了 scipy,它生成了一个包含 4 个数字的元组。最后我尝试了 Mathematica (EllipticPi),它只产生一个值。

from mpmath import ellippi,ellipk
import numpy as np

r=1
rp=2
z=5
zp=7

gamma=zp-z
a=np.sqrt(gamma**2+(rp+r)**2)
c=np.sqrt(gamma**2+r**2)
n1=np.sqrt(2*r/np.abs(r-c))
k=np.sqrt(4*r*rp/a**2)
sn = ellippi(n1**2,k)

print(sn)
r = 1;
rp = 2;
z = 5;
zp = 7;
gamma = zp - z;
a = Sqrt[gamma^2 + (rp + r)^2];
b = rp + r;
c = Sqrt[gamma^2 + r^2];
n1 = Sqrt[2*r/Abs[(r - c)]];
k = Sqrt[4*r*rp/a^2];
N[EllipticPi[n1^2, k]]

我的问题是:

  1. mpmath.ellippi 和 scipy.special.elliprj 之间有什么区别
  2. 我应该使用 scipy pacakge 以及如何将 4 数字元组转换为一个数字?
  3. 为什么 scipy 产生 4 个数字,而 Matematica 只产生 1 个数字?
python scipy wolfram-mathematica elliptic-curve mpmath
1个回答
0
投票

SciPy 计算更通用的积分(Carlson's)。这些积分对于一般参数来说很难看,并且,如果您只需要第三类椭圆积分,则不需要处理这些。

Mathematica 为您提供的内容与卡尔森积分(

scipy.special
提供的内容)之间的关系是

def ellippi(n, m):
  return special.elliprf(                                                                                                                                                                                        
        0., 1. - m, 1.) + (n / 3.) * special.elliprj(0., 1. - m, 1., 1. - n)

这也是

mpmath
给出的带有两个参数的调用,其中
n
是“特征”,
m
是“参数”,即椭圆模平方。

请注意,SciPy 不再支持 Python 2.7,因此使用旧版 Python 运行此代码可能会导致找不到“scipy.special.ellipr*”模块。

© www.soinside.com 2019 - 2024. All rights reserved.