[Python] Gauss guadrature


[Python] Gauss guadrature

파이썬을 이용하여 Gauss quadrature 적분값을 계산해보고 오차를 확인해보겠다. 주어진 함수 및 적분구간은 아래와 같다. n = 5, 9 일때 Gauss-Legendre quadrature 적분값을 계산해보자. import numpy as np import scipy.integrate as spi # f(x) 정의 def f(x): return np.log(x) / x # Gauss quadrature 정의. 함수,구간,point 수 입력 def gauss_quadrature(f, a, b, n): nodes, weights = np.polynomial.legendre.leggauss(n) scaled_nodes = 0.5 * (b - a) * nodes + 0.5 * (a + b) result = np.sum(weights * f(scaled_nodes)) result *= 0.5 * (b - a) return result # 적분 구간 및 point 수 정의. a = 1...


#Gauss #Legendre #Python #quadrature #코딩 #파이썬

원문링크 : [Python] Gauss guadrature