function slide=FoV_demo
% This is a slideshow for the command FoV_asymptotic_factor
% To see it run, type 'FoV-demo', 
%
% [asymptotic_factor] = FoV_asymptotic_factor(A,param)
% computes the asymptotic factor in a FoV (=field-of-value) analysis of GMRES
% applied to a linear system of the form Ax=b
%
% A : the matrix
% param : a vector of parameters of length 1 or 2 (optional)
% param(1): the maximum number of edges of the polygon approaching the FoV of A (10 by defaults)
%           the computation of this polygon uses the matlab function eigs for computing largest 
%           eigenvalues of the real part of e^{-it} A
% param(2) \in \{ 0,1,... \} (default 0): 
%           indicates in which figure the FoV should be plotted 
%           (=0 default figure, <0: no plot)
%
% This program only works if one has installed before the sc toolbox of Toby Driscoll, see his Webpage 
% and if one has added via the matlab command "addpath" the directory of this toolbox to the path
%
% Bernd Beckermann, bbecker@math.univ-lille1.fr, April 13, 2005


% Copyright (c) 1984-98 by The MathWorks, Inc.
if nargout<1,
  playshow FoV_demo
else
  %========== Slide 1 ==========

  slide(1).code={
   '' };
  slide(1).text={
   'This is a demo for the command',
   '     FoV_asymptotic_factor(A)',
   'It requires to install first the Schwartz-Christoffel toolbox of Toby Driscoll.',
   '',
   'Also, one has to add by the matlab command',
   '    addpath(...)',
   'the path to this toolbox.',
   '',
   'Press "Start" to begin.',
   '',
   ''};

  %========== Slide 2 ==========

  slide(2).code={
   'N=20;',
   'A=rand(N,N)+4*eye(N);',
   'FoV_asymptotic_factor(A);' };
  slide(2).text={
   'Here is a simple example with a random matrix of size 20, which is shifted by 4 times the identity in order to get the origin out of the field of values',
   '>> N=20;',
   '>> A=rand(N,N)+4*eye(N);',
   '>> FoV_asymptotic_factor(A);',
   ''};

  %========== Slide 3 ==========

  slide(3).code={
   'FoV_asymptotic_factor(A,20);',
   '' };
  slide(3).text={
   'One may increase the precision of the polygon containing the FoV by adding an optional parameter giving the maximum of vertices',
   '>> FoV_asymptotic_factor(A,20);',
   '',
   'Notice that then the polygon becomes in general smaller, meaning that the asymptotic convergence factor increases.'};

  %========== Slide 4 ==========

  slide(4).code={
   'N=20;',
   'A=rand(N,N);',
   'FoV_asymptotic_factor(A,20);' };
  slide(4).text={
   'The computations become more complicated (and fails sometimes) if the origin is close to the polygon',
   '... and one obtains an error message if 0 lies in the polygon',
   '>> N=20;',
   '>> A=rand(N,N);',
   '>> FoV_asymptotic_factor(A,20);'};

  %========== Slide 5 ==========

  slide(5).code={
   'n=50;e = ones(n,1);',
   'A = spdiags([e -7*e 5*e], -1:1, n, n);',
   'FoV_asymptotic_factor(A);',
   '' };
  slide(5).text={
   'We now use for further illustrations nonsymmetric Toeplitz matrices, which for large dimension behave like Toeplitz operators. For the latter, it is known that the FoV equals the convex hull of the spectrum.',
   '',
   '>> n=50;e = ones(n,1);',
   '>> A = spdiags([e -7*e 5*e], -1:1, n, n);',
   '>> FoV_asymptotic_factor(A);',
   '',
   'For tridiagonal Toeplitz operators, the FoV is an ellipse.'};

  %========== Slide 6 ==========

  slide(6).code={
   'n=200;e = ones(n,1);',
   'A = spdiags([e -7*e 5*e], -1:1, n, n);',
   'FoV_asymptotic_factor(A,20);',
   '' };
  slide(6).text={
   'We use eigs to approach the FoV, which for higher dimensions takes a bit more time.',
   '',
   '>> n=200;e = ones(n,1);',
   '>> A = spdiags([e -7*e 5*e], -1:1, n, n);',
   '>> FoV_asymptotic_factor(A,20);',
   '',
   'This looks a bit more like an ellipse.'};

  %========== Slide 7 ==========

  slide(7).code={
   'N=60;',
   'A=spalloc(N,N,3*N);',
   'for j=1:N/2',
   '   A(2*j-1,2*j-1)=2;',
   '   A(2*j,2*j)=1+2*i;',
   '   A(2*j-1,2*j)=i;',
   '   A(2*j,2*j-1)=i;',
   'end;',
   'for j=1:N/2-1',
   '   A(2*j+1,2*j)=sqrt(1+i);',
   '   A(2*j,2*j+1)=sqrt(1+i);',
   'end;',
   '',
   'FoV_asymptotic_factor(A,[20,7]);' };
  slide(7).text={
   'Finally we have an example of a two-periodic complex Jacobi matrix A being hightly non-normal (a tridiagonal matrix with Toeplitz block structure and blocks of size 2x2), of dimension 60.',
   '>> FoV_asymptotic_factor(A,[20,7]);',
   'Here we use 20 vertices since the structure of the numerical range is not so obvious.',
   'Notice the second parameter which allows to display in a different figure',
   '',
   '',
   '',
   'N=60;',
   'A=spalloc(N,N,3*N);',
   'for j=1:N/2',
   '   A(2*j-1,2*j-1)=2; A(2*j,2*j)=1+2*i;',
   '   A(2*j-1,2*j)=i;   A(2*j,2*j-1)=i; end;',
   'for j=1:N/2-1',
   '   A(2*j+1,2*j)=sqrt(1+i); A(2*j,2*j+1)=sqrt(1+i); end;'} 
end