栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

Tanh-sinh quadrature(The Double Exponential Formulas)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Tanh-sinh quadrature(The Double Exponential Formulas)

Tanh-sinh quadrature(The Double Exponential Formulas for Numerical Integration)

见维基百科
https://en.m.wikipedia.org/wiki/Tanh-sinh_quadrature

见Tanh-sinh quadrature numerical integration method converging to wrong value
https://www.e-learn.cn/topic/2848897

见Stackoverflow
https://stackoverflow.com/questions/24986588/tanh-sinh-quadrature-numerical-integration-method-converging-to-wrong-value

参考文献

参考文献

测试如下(采用Python高精度浮点算法包 mpmath)

# -*- coding: utf-8 -*-
"""
Created on Fri Oct 22 20:14:43 2021

      I=Int_{a}^{b} f(z)dz
   其中
       a
   
"""
from mpmath import mp,mpf,cosh,sinh,pi,tanh,sqrt
if(1):
    

    mp.dps = 100
    
    h = mpf(2**-12);#
    
    def weights(k):
        num = mpf(0.5)*h*pi*cosh(k*h)
        den = cosh(mpf(0.5)*pi*sinh(k*h))**2
        return (num/den)
    
    def abscissas(k,a,b):
        f=((b-a)/2)*(tanh(mpf(0.5)*pi*sinh(k*h)))+(b+a)/2
        return f
    
    def f(x):
        return 1/sqrt(1 - mpf(x)**2)
    
    N = 20000
    #通过作线性变换,求任意区间的数值积分
    a=0
    b=1
    result = 0
    for k in range(-N, N+1):
        result = result + weights(k)*f(abscissas(k,a,b))*(b-a)/2
    print(result)
    print(result - pi)
'''```
#可以发现对N的要求很高,且很慢
#N=20000
3.141592653589793238462643383279502884197169395623305210054471789091557055855748154170301951289498386
-3.751800610920472803216259350430460844457732874052618682441090144344372471319795201134275503228835472e-45
#N=2000
1.449489205637340355829215405535223522203982454439832629403540056142008755610237611478998353099179717
-1.692103447952452882633427977744279361993186944935273191571404536165807650675971387149036472242937351

#N=200
0.1536915064631849189177884604412165536645462018136925450754802115004847789524209471365251505235660057
-2.987901147126608319544854922838286330532623197561413275899464380807331627333788051491509674818551062
'''
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/349655.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号