
function demo_trigauss_error

n=10;
alpha=0; beta=pi/30;
f=@(x) sin(20*x)+cos(100*x);
g=@(x) (-1/20)*cos(20*x)+(1/100)*sin(100*x);
Iex=feval(g,beta)-feval(g,alpha);

% TEST KRONROD.
fprintf('\n \t >> LEGENDRE-KRONROD');
test_kronrod(f,n,alpha,beta,Iex);

% TEST ANTILEGENDRE.
fprintf('\n \t >> ANTILEGENDRE');
test_antigauss(f,n,alpha,beta,Iex);

% TEST TRIG KRONROD.
fprintf('\n \t >> TRIG-KRONROD');
test_trig_kronrod(f,n,alpha,beta,Iex);

% TEST ANTITRIGAUSS.
fprintf('\n \t >> ANTITRIG');
test_antitrigauss(f,n,alpha,beta,Iex);







function test_kronrod(f,n,alpha,beta,Iex)

% TEST KRONROD.

% format long e

twGK=trigauss(n,alpha,beta,'kronrod');

xx=twGK(:,1);
fxx=feval(f,xx);

wlow=twGK(2:2:end,3);
fxx_low=fxx(2:2:end);

Ilow=wlow'*fxx_low;

whigh=twGK(:,2);

Ihigh=whigh'*fxx;

errest=Ilow-Ihigh;
err=Ilow-Iex;
errh=Ihigh-Iex;

fprintf('\n \t DEG: %5.0f ALPHA: %1.5e BETA: %1.5e',n,alpha,beta);
fprintf('\n \t DIM KR: %5.0f',length(whigh));
fprintf('\n \t DIM GL: %5.0f',length(wlow));
fprintf('\n \t * I LOW : %1.15e',Ilow);
fprintf('\n \t * I HIGH: %1.15e',Ihigh);
fprintf('\n \t * I EXCT: %1.15e',Iex);
fprintf('\n \t AE EST: %2.12e',errest);
fprintf('\n \t AE LOW: %2.12e',err);
fprintf('\n \t RE EST: %2.12e',errest/Ihigh);
fprintf('\n \t RE LOW: %2.12e',err/Iex);
fprintf('\n \t ** AE HGH: %2.12e',errh);
fprintf('\n \t ** RE HGH: %2.12e  \n',errh/Iex);








function test_antigauss(f,n,alpha,beta,Iex)

% TEST ANTIGAUSS.

% format long e

twAGf=trigauss(n,alpha,beta,'antigauss');

tAG=twAGf(:,1); wAG=twAGf(:,2);
tG=twAGf(1:end-1,3); wG=twAGf(1:end-1,4);

fAG=feval(f,tAG); fG=feval(f,tG);

Ilow=wG'*fG;
Ihigh=wAG'*fAG;

Ibetter=(Ilow+Ihigh)/2;

errest=Ilow-Ihigh;
err=Ilow-Iex;
errbetter=Ibetter-Iex;
errh=Ihigh-Iex;

fprintf('\n \t DEG: %5.0f ALPHA: %1.5e BETA: %1.5e',n,alpha,beta);
fprintf('\n \t DIM AG: %5.0f',length(wAG));
fprintf('\n \t DIM GL: %5.0f',length(wG));
fprintf('\n \t * I LOW : %1.15e',Ilow);
fprintf('\n \t * I HIGH: %1.15e',Ihigh);
fprintf('\n \t * I AVER: %1.15e',Ibetter);
fprintf('\n \t * I EXCT: %1.15e',Iex);

fprintf('\n \t AE EST: %2.12e',errest);
fprintf('\n \t AE    : %2.12e',err);
fprintf('\n \t AE AVR: %2.12e',errbetter);
fprintf('\n \t RE EST: %2.12e',errest/Ihigh);
fprintf('\n \t RE    : %2.12e',err/Iex);

fprintf('\n \t ** AE HGH: %2.12e',errh);
fprintf('\n \t ** RE HGH: %2.12e  \n',errh/Iex);



function test_trig_kronrod(f,n,alpha,beta,Iex)


twTK=trigauss(n,alpha,beta,'trig_kronrod');
xx=twTK(:,1);
fxx=feval(f,xx);

wlow=twTK(2:2:end,3);
fxx_low=fxx(2:2:end);

Ilow=wlow'*fxx_low;

whigh=twTK(:,2);

Ihigh=whigh'*fxx;

errest=Ilow-Ihigh;
err=Ilow-Iex;
errh=Ihigh-Iex;

fprintf('\n \t DEG: %5.0f ALPHA: %1.5e BETA: %1.5e',n,alpha,beta);
fprintf('\n \t DIM KR: %5.0f',length(whigh));
fprintf('\n \t DIM GL: %5.0f',length(wlow));
fprintf('\n \t * I LOW : %1.15e',Ilow);
fprintf('\n \t * I HIGH: %1.15e',Ihigh);
fprintf('\n \t * I EXCT: %1.15e',Iex);
fprintf('\n \t AE EST: %2.12e',errest);
fprintf('\n \t AE    : %2.12e',err);
fprintf('\n \t RE EST: %2.12e',errest/Ihigh);
fprintf('\n \t RE    : %2.12e',err/Iex);
fprintf('\n \t ** AE HGH: %2.12e',errh);
fprintf('\n \t ** RE HGH: %2.12e  \n',errh/Iex);








function test_antitrigauss(f,n,alpha,beta,Iex)

% TEST ANTIGAUSS.

% format long e

twAGf=trigauss(n,alpha,beta,'antitrigauss');

tAG=twAGf(:,1); wAG=twAGf(:,2);
tG=twAGf(1:end-1,3); wG=twAGf(1:end-1,4);

fAG=feval(f,tAG); fG=feval(f,tG);

Ilow=wG'*fG;
Ihigh=wAG'*fAG;

Ibetter=(Ilow+Ihigh)/2;

errest=Ilow-Ihigh;
err=Ilow-Iex;
errbetter=Ibetter-Iex;
errh=Ihigh-Iex;

fprintf('\n \t DEG: %5.0f ALPHA: %1.5e BETA: %1.5e',n,alpha,beta);
fprintf('\n \t DIM AG: %5.0f',length(wAG));
fprintf('\n \t DIM GL: %5.0f',length(wG));
fprintf('\n \t * I LOW : %1.15e',Ilow);
fprintf('\n \t * I HIGH: %1.15e',Ihigh);
fprintf('\n \t * I AVER: %1.15e',Ibetter);
fprintf('\n \t * I EXCT: %1.15e',Iex);

fprintf('\n \t AE EST: %2.12e',errest);
fprintf('\n \t AE    : %2.12e',err);
fprintf('\n \t AE AVR: %2.12e',errbetter);
fprintf('\n \t RE EST: %2.12e',errest/Ihigh);
fprintf('\n \t RE    : %2.12e',err/Iex);
fprintf('\n \t ** AE HGH: %2.12e',errh);
fprintf('\n \t ** RE HGH: %2.12e  \n',errh/Iex);
