python function gamma_Python sympy.gamma方法代码示例

本文提供了一个Python代码示例,演示如何使用sympy库的gamma方法来测试Gautschi的高斯积分公式。通过导入sympy模块,定义测试函数并计算权重函数exp(-t**3/3)的矩,然后从节点和权重中获取系数,最后检查这些系数的准确性。
摘要由CSDN通过智能技术生成

# 需要导入模块: import sympy [as 别名]

# 或者: from sympy import gamma [as 别名]

def test_gautschi_how_to_and_how_not_to():

"""Test Gautschi's famous example from

W. Gautschi,

How and how not to check Gaussian quadrature formulae,

BIT Numerical Mathematics,

June 1983, Volume 23, Issue 2, pp 209–216,

.

"""

points = numpy.array(

[

1.457697817613696e-02,

8.102669876765460e-02,

2.081434595902250e-01,

3.944841255669402e-01,

6.315647839882239e-01,

9.076033998613676e-01,

1.210676808760832,

1.530983977242980,

1.861844587312434,

2.199712165681546,

2.543839804028289,

2.896173043105410,

3.262066731177372,

3.653371887506584,

4.102376773975577,

]

)

weights = numpy.array(

[

3.805398607861561e-2,

9.622028412880550e-2,

1.572176160500219e-1,

2.091895332583340e-1,

2.377990401332924e-1,

2.271382574940649e-1,

1.732845807252921e-1,

9.869554247686019e-2,

3.893631493517167e-2,

9.812496327697071e-3,

1.439191418328875e-3,

1.088910025516801e-4,

3.546866719463253e-6,

3.590718819809800e-8,

5.112611678291437e-11,

]

)

# weight function exp(-t**3/3)

n = len(points)

moments = numpy.array(

[3.0 ** ((k - 2) / 3.0) * math.gamma((k + 1) / 3.0) for k in range(2 * n)]

)

alpha, beta = quadpy.tools.coefficients_from_gauss(points, weights)

# alpha, beta = quadpy.tools.chebyshev(moments)

errors_alpha, errors_beta = quadpy.tools.check_coefficients(moments, alpha, beta)

assert numpy.max(errors_alpha) > 1.0e-2

assert numpy.max(errors_beta) > 1.0e-2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值