繁体   English   中英

使用四边形(scipy.integrate)和小数

[英]Using quad (scipy.integrate) and decimals

我需要高度精确地集成一个函数,例如:

from decimal import * 
from scipy.integrate import quad
getcontext().prec = 30
a = Decimal('1.1') + Decimal('1.2') 
print type(a)

def f(X):
    return quad(lambda x: X, 0, 1)[0]

b = f(a)
print "{0:.30f}".format(b), type(b)

我得到

<class 'decimal.Decimal'>
2.300000000000000266453525910038 <type 'float'>

我想使用Quad作为我的集成工具,但不幸的是,似乎将输出转换为浮点型。 我希望积分的输出具有更高的精度。 我该如何实现?

我将看看使用mpmath库。 它支持高精度集成( http://mpmath.org/doc/0.19/calculus/integration.html )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM