最近因改作业的需要,编了个MATLAB小程序,可计算高斯积分点坐标和权。感兴趣的网友或同学可参考。
function [ti,Ai] = GaussPoint(n)
%Purpose:
% compute coordinates and weights of Gauss points
%Input:
% n: number of Gauss points requested
%Output:
% ti: Coordinates of Gauss points
% Ai: weights of Gauss points
%Copywright
% Yansheng Jiang 2006, version 2.0
%
if n > 44
error('The number of Gauss points requested is too high.');
end
pnCoef = zeros(1,n+1);
dpnCoef = pnCoef;
odd = mod(n,2) == 1;
if odd
lastp = (n-1)/2;
else
lastp = n/2;
end
for p = 0:lastp
i = 2*p + 1;
pnCoef(i) = pnCoef(i) + ...
(-1)^p*factorial(2*n-2*p)/(2^n*factorial(p)*factorial(n-p)*factorial(n-2*p));
dpnCoef(i) = pnCoef(i)*(n-2*p);
end
ti = roots(pnCoef);
tiPowers = zeros(n,n);
for point = 1:n
for expoent = 1:n
tiPowers(point,expoent) = ti(point)^(n-expoent);
end
end
dpn = dpnCoef(1:n) * tiPowers';
Ai = 2./((1-ti.^2).*(dpn.^2)');
最后修改于 2006-12-04 09:57
阅读(?)评论(0)