0001 function [x,w] = gauleg_dke_yp(n,epsi,x1,x2)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 if nargin < 0,
0026 infoyp(2,'Wrong number of input arguments for gaulegyp');
0027 return;
0028 end
0029 if nargin == 0,
0030 n = 50;
0031 epsi = 1e-14;
0032 x1 = -1;
0033 x2 = 1;
0034 elseif nargin == 1,
0035 epsi = 1e-14;
0036 x1 = -1;
0037 x2 = 1;
0038 elseif nargin == 2,
0039 x1 = -1;
0040 x2 = 1;
0041 elseif nargin == 3,
0042 x2 = 1;
0043 end
0044
0045 m = (n+1)/2;
0046 xm = 0.5*(x2+x1);xl = 0.5*(x2-x1);
0047 for i=1:m,
0048 z = cos(pi*(i-0.25)/(n+0.5));
0049 p1 = 1.0;
0050 p2 = 0.0;
0051 for j=1:n,
0052 p3 = p2;p2 = p1;p1 = ((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j;
0053 end
0054 pp = n*(z*p1-p2)/(z*z-1.0);z1 = z;z = z1-p1/pp;
0055 test = abs(z-z1)-epsi;
0056 while test > 0,
0057 p1 = 1.0;p2 = 0.0;
0058 for j=1:n
0059 p3 = p2;p2 = p1;p1 = ((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j;
0060 end
0061 pp = n*(z*p1-p2)/(z*z-1.0);z1 = z;z = z1-p1/pp;
0062 test = abs(z-z1)-epsi;
0063 end
0064 x(i) = xm-xl*z;x(n+1-i) = xm+xl*z;
0065 w(i) = 2.0*xl/((1.0-z*z)*pp*pp);w(n+1-i) = w(i);
0066 end
0067
0068 x = x(:);
0069 w = w(:);