specialpython_Python special.j1方法代码示例

本文展示了如何在Python中使用scipy.special模块的j1函数进行积分计算。通过导入scipy.special并定义不同的积分核函数,如quad_PJ0和quad_PJ1,对Hankel变换进行求解。示例中使用了integrate.quad进行数值积分,并处理可能的不收敛情况。
摘要由CSDN通过智能技术生成

# 需要导入模块: from scipy import special [as 别名]

# 或者: from scipy.special import j1 [as 别名]

def quad(sPJ0r, sPJ0i, sPJ1r, sPJ1i, sPJ0br, sPJ0bi, ab, off, ang_fact, iinp):

r"""Quadrature for Hankel transform.

This is the kernel of the QUAD method, used for the Hankel transforms

:func:`hankel_quad` and :func:`hankel_qwe` (where the integral is not

suited for QWE).

"""

# Define the quadrature kernels

def quad_PJ0(klambd, sPJ0, koff):

r"""Quadrature for PJ0."""

return sPJ0(np.log(klambd))*special.j0(koff*klambd)

def quad_PJ1(klambd, sPJ1, ab, koff, kang):

r"""Quadrature for PJ1."""

tP1 = kang*sPJ1(np.log(klambd))

if ab in [11, 12, 21, 22, 14, 24, 15, 25]: # Because of J2

# J2(kr) = 2/(kr)*J1(kr) - J0(kr)

tP1 /= koff

return tP1*special.j1(koff*klambd)

def quad_PJ0b(klambd, sPJ0b, koff, kang):

r"""Quadrature for PJ0b."""

return kang*sPJ0b(np.log(klambd))*special.j0(koff*klambd)

# Pre-allocate output

conv = True

out = np.array(0.0+0.0j)

# Carry out quadrature for required kernels

iinp['full_output'] = 1

if sPJ0r is not None:

re = integrate.quad(quad_PJ0, args=(sPJ0r, off), **iinp)

im = integrate.quad(quad_PJ0, args=(sPJ0i, off), **iinp)

out += re[0] + 1j*im[0]

# If there is a fourth output from QUAD, it means it did not converge

if (len(re) or len(im)) > 3:

conv = False

if sPJ1r is not None:

re = integrate.quad(quad_PJ1, args=(sPJ1r, ab, off, ang_fact), **iinp)

im = integrate.quad(quad_PJ1, args=(sPJ1i, ab, off, ang_fact), **iinp)

out += re[0] + 1j*im[0]

# If there is a fourth output from QUAD, it means it did not converge

if (len(re) or len(im)) > 3:

conv = False

if sPJ0br is not None:

re = integrate.quad(quad_PJ0b, args=(sPJ0br, off, ang_fact), **iinp)

im = integrate.quad(quad_PJ0b, args=(sPJ0bi, off, ang_fact), **iinp)

out += re[0] + 1j*im[0]

# If there is a fourth output from QUAD, it means it did not converge

if (len(re) or len(im)) > 3:

conv = False

# Collect the results

return out, conv

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值