function demo_antigaussian(f,alpha,beta,N)

% Integration of a function 'f' in [-1,1] and Gauss-Kronrod rules.
if nargin < 1, f=@(x) exp(x); end
if nargin < 3, alpha=0; beta=0; end % Jacobi weight
if nargin < 4, N=3; end

dim=N+1; % length Kronrod rule
ab=r_jacobi(dim,alpha,beta); % Gauss-Legendre recurrence (as required by kronrod)
xwg=gauss(N,ab(1:N,:));
ab_agss=ab; ab_agss(end,2)=2*ab_agss(end,2);
xwag=gauss(N+1,ab_agss);

g=@(x) f(x).*(1-x).^alpha.*(1+x).^beta;
I=integral(g,-1,1,'AbsTol',10^(-15),'RelTol',10^(-15));

fg=feval(f,xwg(:,1)); % this evaluation includes that at Gauss-Legendre nodes!
Sg=(xwg(:,2))'*fg;

fg=feval(f,xwag(:,1)); % this evaluation includes that at anti-gauss nodes!
Sag=(xwag(:,2))'*fg;

fprintf('\n * Gauss-Legendre rule \n \n'); xwg
fprintf('\n * Gauss-Legendre-anti rule \n \n'); xwag
fprintf('\n \t I gauss    : %1.15e',Sg);
fprintf('\n \t I agaus    : %1.15e',Sag);
fprintf('\n \t I exact    : %1.15e',I);
fprintf('\n \n');
fprintf('\n \t I-Sg       : %1.3e',(I-Sg));
fprintf('\n \t I-Sag      : %1.3e',(I-Sag));
fprintf('\n \t (Sg+Sag)/2 : %1.3e',(Sag-Sg)/2);
fprintf('\n \n');
