n=10;                               % dimension of the problem
rootp=1-2*rand(n,1);                % generate a random vector of roots
coeff=poly(rootp);                  % find the corresponding coefficients
coeff=coeff./coeff(1);              % make the polynomial monic
coeff=fliplr(coeff);                % flip the vector of coefficients
A=diag(ones(n-1,1),1);              % construct companion matrix
A(end,:)=-coeff(1:end-1);
u0=zeros(n,1);                      % initial guess for gmres
f=zeros(n,1); f(1)=1;               % right-hand side vector equal to e1 
[u,uk,res]=GMRES(A,f,u0,1e-16,n);
plot(0:n,res,'o-b','Linewidth',2);  % plot gmres residuals
grid on;
xlabel('iterations');
ylabel('residual');
set(gca,'fontsize',14);             % enlarge the size of the text
