栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

numpy中高斯-勒让德正交的不同间隔

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

numpy中高斯-勒让德正交的不同间隔

要更改间隔,请使用以下方法将x值从[-1,1]转换为[a,b]:

t = 0.5*(x + 1)*(b - a) + a

然后将正交公式缩放为(b-a)/ 2:

gauss = sum(w * f(t)) * 0.5*(b - a)

这是您的示例的修改版本:

import numpy as npfrom scipy import integrate# Define function and intervala = 0.0b = np.pi/2f = lambda x: np.cos(x)# Gauss-Legendre (default interval is [-1, 1])deg = 6x, w = np.polynomial.legendre.leggauss(deg)# Translate x values from the interval [-1, 1] to [a, b]t = 0.5*(x + 1)*(b - a) + agauss = sum(w * f(t)) * 0.5*(b - a)# For comparisonquad, quad_err = integrate.quad(f, a, b)print 'The QUADPACK solution: {0:.12} with error: {1:.12}'.format(quad, quad_err)print 'Gauss-Legendre solution: {0:.12}'.format(gauss)print 'Difference between QUADPACK and Gauss-Legendre: ', abs(gauss - quad)

它打印:

QUADPACK解决方案:1.0,错误:1.11022302463e-14高斯-勒根德雷解决方案:1.0QUADPACK和Gauss-Legendre之间的差异:4.62963001269e-14


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662000.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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