Gauss-Legendre integration in Pythonのコード
724 ワード
コードの余暇時間、コードの過程の重要ないくつかのコードを収蔵して、以下のコードはGauss-Legendre integration in Pythonのコードについてで、小さい仲間に対しても役に立つことを望みます.
''' I = gaussQuad2(f,xc,yc,m).
Gauss-Legendre integration of f(x,y) over a
quadrilateral using integration order m.
{xc},{yc} are the corner coordinates of the quadrilateral.
'''
from numpy import zeros,dot
def gaussQuad2(f,x,y,m):
def jac(x,y,s,t):
J = zeros((2,2))
def map(x,y,s,t):
N = zeros(4)
xCoord = dot(N,x)
yCoord = dot(N,y)
return xCoord,yCoord
s,A = gaussNodes(m)
sum = 0.0
for i in range(m):
for j in range(m):
xCoord,yCoord = map(x,y,s[i],s[j])
return sum