% The main program for solving Toeplitz systems T\bu = {\bf b}.
clear           % release all variables from the Matlab workspace
tol = 1.0e-7;   % the tolerance for the PCG method
it_max = 4000;  % the maximum number of iterations for the PCG method

n = input('input the size of the Toeplitz system n: ');
disp('choice of preconditioners: ');
disp('0: no preconditioner');
disp('1: T. Chan preconditioner');
disp('2: Strang preconditioner');
disp('3: R. Chan preconditioner');
disp('4: Modified Dirichlet kernel');
disp('5: De la Vallee Poussin kernel');
disp('6: von Hann kernel');
disp('7: Hamming kernel');
disp('8: Bernstein kernel');
disp('9: Generalized Jackson kernel, r=2');
disp('10: Generalized Jackson kernel, r=3');
disp('11: Generalized Jackson kernel, r=4');
disp('12: superoptimal preconditioner');

pchoice = input('input a preconditioner (pchoice): 0~12:  ');

fprintf('\n');
disp('choice of entries for Toeplitz matrices: ');
disp('1: for results in Table 2.1');
disp('2: for results in Table 3.3');
disp('3: for results in Table 3.4');
disp('4: for results in Table 4.1 with f(x)=x^4+1');
disp('5: for results in Table 4.1 with f(x)=|x|^3+0.01');
disp('6: for results in Table 4.2 with f(x)=x^2');
disp('7: for results in Table 4.2 with f(x)=x^2(pi^4-x^4)');
disp('8: for results in Table 4.3 with f(x)=x^4');
disp('9: for results in Table 4.3 with f(x)=x^4(pi^2-x^2)');
disp('10: for results in Table 4.4 with f(x)=|x|^3');
disp('11: for results in Table 4.4 with f(x)=sigma-0.3862');

fchoice = input('input an example (fchoice): 1~11:  ');

t = kern(n,fchoice); % t is the first column of the Teoplitz matrix T
b = ones(n,1);       % the right-hand side vector b

[gev,ev] = genevs(t,pchoice);     % compute the eigenvalues, see A.3
ig = zeros(n,1);                  % the initial guess

u = pcg(gev,ev,b,ig,tol,it_max);  % call the PCG method
