% TABLE2_5 Computation of Table 2.5.
%
f1='%6.0f %3.0f %9.2e %9.2e %9.2e\n';
f2='%10.0f %9.2e %9.2e %9.2e\n';
fprintf('\n')
disp('   Table 2.5 Condition number and error')
disp('   magnification for discrete N-point')
disp('   Chebyshev measure on [0,1) using')
disp('   Legendre moments')
fprintf('\n')
disp('     N   n  (2.1.50)    maga      magb')
NN=[10 20 40 80];
for k=1:4
  if k==1
    nn=[5 10];
  elseif k==2
    nn=[5 10 15 20];
  elseif k==3
    nn=[5 10 15 25 35];
  else
    nn=[10 20 30 40 50];
  end
  N=NN(k); mom=zeros(1,2*N); P=zeros(2*N,N);
  ab=r_hahn(N-1); ab(:,1)=ab(:,1)/N;
  ab(1,2)=ab(1,2)/N; ab(2:N,2)=ab(2:N,2)/(N^2);
  abj=r_jacobi01(2*N);
  for s=1:N
    t=(s-1)/N;
    P(1,s)=1; P(2,s)=t-abj(1,1);
    for r=2:2*N-1
      P(r+1,s)=(t-abj(r,1))*P(r,s)-abj(r,2)*P(r-1,s);
    end
  end
  for r=1:2*N
    mom(r)=sum(P(r,:))/N;
  end
  for n=nn
    [abcheb,normsq]=chebyshev(n,mom,abj);
    errab=abs(abcheb-ab(1:n,:))./moll(ab(1:n,:));
    maga=max(errab(:,1)/eps);
    magb=max(errab(:,2)/eps);
    ac=acondG(n,ab,abj);
    if n==nn(1)
      fprintf(f1,N,n,ac,maga,magb)
    else
      fprintf(f2,n,ac,maga,magb)
    end
  end
  fprintf('\n')
end
