## Copyright (C) 2017 Mustafa Turhan Çoban
## Created: 2017-08-25

function [a] = gauss_legendre_cof (x1,x2,n)
##calculates legendre gauss-coefficients as coefficients of the integral
##for n terms
eps=3e-15;
 nmax=100;
m=(n+1.0)/2.0;
xm=0.5*(x2+x1);
xl=0.5*(x2-x1);
for i=1:m
    z=cos(pi*((i-0.25)/(n+0.5)));
		for ii=0:nmax
		    p1=1.0;
		    p2=0.0;
		    for j =1:n
			     p3=p2;
		  	   p2=p1;
			     p1=((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j;
        endfor
		   pp=n*(z*p1-p2)/(z*z-1.0);
		   z1=z;
		   z=z1-p1/pp;
       if abs(z-z1) < eps break; endif
    endfor
		a(1,i)=xm-xl*z;
		a(1,n+1-i)=xm+xl*z;
		a(2,i)=2.0*xl/((1.0-z*z)*pp*pp);
		a(2,n+1-i)=a(2,i);
    endfor
endfunction
