function [ val ] = tgallery(varargin)
% [ val ] = tgallery( what, dim, N, seed, para5 )
% Returns sets of matrices, mostly used for tjsr.
%
% Input:
%   what        string which controls the return value
%   dim         dimension of the returned value (if applicable), 
%   N           number of matrices which shall be returned
%   seed        seed for the random number generator
%
% Output:    
%   val         depends on "what" and the given parametrs
%
% E.g.:  tgallery('rand_rho',5,2,100)
%
% Written by: tommsch, 2018

%#ok<*AGROW>


    if(nargin>=4); seed_4thargument=varargin{4}; rng(mod(seed_4thargument,2^30)); rand(1000); end; %call randi(10000) to start Mersenne Twister
    if(nargin>=3); N_3rdargument=varargin{3}; end;
    if(nargin>=2); dim_2ndargument=varargin{2}; end;
    if(nargin>=1); what_1stargument=varargin{1}; end;

    %Random matrices, need two arguments 'rand_XXX',<dim>,<number of matrices>
    if(strcmp(what_1stargument,'rand_stochastic'));     val=matrix_stochastic(dim_2ndargument, N_3rdargument); return; end;        %Stochastic matricesTransition matrices with mask length dim, dilation=N;
    if(strcmp(what_1stargument,'rand_doublestochastic')); val=matrix_doublestochastic(dim_2ndargument, N_3rdargument); return; end;        %Double stochastic matrices
    if(strcmp(what_1stargument,'rand_stochastic_neg')); val=matrix_stochastic_neg(dim_2ndargument, N_3rdargument); return; end;        %Stochastic matricesTransition matrices with mask length dim, dilation=N;
    if(strcmp(what_1stargument,'rand_doublestochastic_neg'));  val=matrix_doublestochastic_neg(dim_2ndargument, N_3rdargument); return; end;        %Double stochastic matrices
    if(strcmp(what_1stargument,'rand_TU'));             val=matrix_TU(dim_2ndargument, N_3rdargument); return; end;        %Transition matrices with mask length dim, dilation=N; dimension is implicitely defined via dilation
    if(strcmp(what_1stargument,'rand_TV0'));            val=matrix_TV0(dim_2ndargument, N_3rdargument); return; end;        %Transition matrices with mask length dim, dilation=N;
    if(strcmp(what_1stargument,'rand_pm1'));            for i=1:N_3rdargument; val{i}=randi(3,dim_2ndargument,dim_2ndargument)-2;   end; return; end;        %random matrix with values -1, 0 1.
    if(strcmp(what_1stargument,'rand_sparse_2'));       for i=1:N_3rdargument; val{i}=(rand(dim_2ndargument)>.5).*(rand(dim_2ndargument)-.5);       end; return; end;        %random sparse matrix with density 0.5
    if(strcmp(what_1stargument,'rand_sparse_2_pos'));   for i=1:N_3rdargument; val{i}=(rand(dim_2ndargument)>.5).*(rand(dim_2ndargument));       end; return; end;        %random sparse positive matrix with density 0.5
    if(strcmp(what_1stargument,'rand_sparse_4'));       for i=1:N_3rdargument; val{i}=(rand(dim_2ndargument)>.75).*(rand(dim_2ndargument)-.5);       end; return; end;        %random sparse matrix with density 0.25
    if(strcmp(what_1stargument,'rand_sparse_4_pos'));   for i=1:N_3rdargument; val{i}=(rand(dim_2ndargument)>.75).*(rand(dim_2ndargument));       end; return; end;        %random sparse positive matrix with density 0.25
    if(strcmp(what_1stargument,'rand_bool'));           for i=1:N_3rdargument; val{i}=randi(2,dim_2ndargument,dim_2ndargument)-1;   end; return; end;        %random boolean matrix
    if(strcmp(what_1stargument,'rand_normal'));         for i=1:N_3rdargument; val{i}=randn(dim_2ndargument);     end; return; end;        %random matrix with values [-.5 .5]
    if(strcmp(what_1stargument,'rand_normal_pos'));     for i=1:N_3rdargument; val{i}=rand(dim_2ndargument);      end; return; end;           %positive random matrix
    if(strcmp(what_1stargument,'rand_norm'));           for i=1:N_3rdargument; val{i}=rand(dim_2ndargument)-.5;   val{i}=val{i}/norm(val{i}); end; return; end;         %random matrices with norm 1 
    if(strcmp(what_1stargument,'rand_norm_pos'));       for i=1:N_3rdargument; val{i}=rand(dim_2ndargument);      val{i}=val{i}/norm(val{i}); end; return; end;         %random matrices with norm 1 
    if(strcmp(what_1stargument,'rand_rho'));            for i=1:N_3rdargument; val{i}=rand(dim_2ndargument)-.5;   val{i}=val{i}/trho(val{i});  end; return; end;           %random matrices with spectral radius 1 
    if(strcmp(what_1stargument,'rand_int1'));           val=matrix_integer(dim_2ndargument, N_3rdargument,1); return; end;      %integer matrices
    if(strcmp(what_1stargument,'rand_unitary'));        val=matrix_unitary(dim_2ndargument, N_3rdargument); return; end;        %Unitary matrices 
    if(strcmp(what_1stargument,'rand_zero'));           val=matrix_zerospectralradius(dim_2ndargument, N_3rdargument); return; end;        %matrices with spectral radius equal zero
    if(strcmp(what_1stargument,'rand_rho_pos'));        for i=1:N_3rdargument; val{i}=rand(dim_2ndargument);      val{i}=val{i}/trho(val{i});  end; return; end;           %random matrices with spectral radius 1 
    if(strcmp(what_1stargument,'rand_sum'));            for i=1:N_3rdargument; val{i}=rand(dim_2ndargument)-.5;   val{i}=val{i}./repmat(sum(val{i}),[dim_2ndargument 1]); end; return; end;           %random matrices with row sum 1 %eg: tgallery('rho',2)
    if(strcmp(what_1stargument,'rand_sum_pos'));        for i=1:N_3rdargument; val{i}=rand(dim_2ndargument);      val{i}=val{i}./repmat(sum(val{i}),[dim_2ndargument 1]); end; return; end;           %random matrices with row sum 1 %eg: tgallery('rho',2)
    if(strcmp(what_1stargument,'gallery_randcolu_1'));  val{1}=gallery('randcolu',dim_2ndargument,dim_2ndargument,0); val{2}=gallery('randcolu',dim_2ndargument,dim_2ndargument,0); return; end; %random n-by-n matrix with columns of unit 2-norm, with random singular values whose squares are from a uniform distribution, contains no zeros
    if(strcmp(what_1stargument,'gallery_randcolu_0'));  val{1}=gallery('randcolu',dim_2ndargument,dim_2ndargument,1); val{2}=gallery('randcolu',dim_2ndargument,dim_2ndargument,1); return; end; %random n-by-n matrix with columns of unit 2-norm, with random singular values whose squares are from a uniform distribution, may contains zeros
    if(strcmp(what_1stargument,'gallery_randcorr_1'));  val{1}=gallery('randcorr',dim_2ndargument,dim_2ndargument,0); val{2}=gallery('randcolu',dim_2ndargument,dim_2ndargument,0); return; end; %random n-by-n correlation matrix with random eigenvalues from a uniform distribution, contains no zeros. Makes maximal trees for high dimensions
    if(strcmp(what_1stargument,'gallery_randcorr_0'));  val{1}=gallery('randcorr',dim_2ndargument,dim_2ndargument,1); val{2}=gallery('randcolu',dim_2ndargument,dim_2ndargument,1); return; end; %random n-by-n correlation matrix with random eigenvalues from a uniform distribution, may contains zeros. Makes maximal trees for high dimensions
    if(strcmp(what_1stargument,'gallery_randhess'));    val{1}=gallery('randhess',dim_2ndargument); val{2}=gallery('randhess',dim_2ndargument); return; end; %random n-by-n real, orthogonal upper Hessenberg matrix.
    if(strcmp(what_1stargument,'rando_1'));             val{1}=gallery('rando',dim_2ndargument,1); val{2}=gallery('rando',dim_2ndargument,1); return; end; %random 0-1 matrix. Interesting for balancing.
    if(strcmp(what_1stargument,'rando_2'));             val{1}=gallery('rando',dim_2ndargument,1); val{2}=gallery('rando',dim_2ndargument,2); return; end; %random 0-1 matrix. Interesting for balancing.
    if(strcmp(what_1stargument,'rando_3'));             val{1}=gallery('rando',dim_2ndargument,1); val{2}=gallery('rando',dim_2ndargument,3); return; end; %random 0-1 matrix. Interesting for balancing.

    %Matrices from matlab gallery
    if(strcmp(what_1stargument,'gallery_clement'));     val{1}=gallery('clement',dim_2ndargument,0); val{2}=gallery('clement',dim_2ndargument,1); return; end;
    if(strcmp(what_1stargument,'gallery_grcar'));       val{1}=gallery('grcar',8,4); val{2}=gallery('grcar',8,5); return; end; %complex eigenvalues
    if(strcmp(what_1stargument,'gallery_lauchli')); 
        if(length(N_3rdargument)==1); error('tgallery: ''gallery_lauchli'' needs a vector as parameter ''N''.'); end;
        for i=1:length(N_3rdargument); val{i}=gallery('lauchli',dim_2ndargument,N_3rdargument(i)); val{i}=val{i}'*val{i}; val{i}=val{i}/trho(val{i}); end;
        return; 
    end; 
    if(strcmp(what_1stargument,'gallery_orthog_1')); val{1}=gallery('orthog',dim_2ndargument,1); val{2}=gallery('orthog',dim_2ndargument,2); return; end; %complex eigenvalues / maximum number of edges
    if(strcmp(what_1stargument,'gallery_orthog_2')); val{1}=gallery('orthog',4,4); val{2}=circshift(val{1},1); return; end; %real eigenvalues, but complex dual eigenvectors
    if(strcmp(what_1stargument,'gallery_orthog_3')); val{1}=gallery('orthog',3,5); val{2}=circshift(val{1},1); return; end; %Polytope is a sphere
    
    


    %Matrices from Examples/Papers
    if(strcmp(what_1stargument,'cex'));      val{1}=sym([1 1; 0 1]);  val{2}=sym('0.749326546330367557943961948091344672091327370236064317358024')*[1 0; 1 1]; return; end;%jsr finitesness conjecture counterexample
    if(strcmp(what_1stargument,'euler'));    val=matrix_euler(dim_2ndargument); return; end;   
    if(strcmp(what_1stargument,'ones'));     val=transitionmatrix({ones(1,dim_2ndargument)',N_3rdargument},'Omega',0:dim_2ndargument-1,'nocheck');val=cellfun(@transpose,val,'uniformoutput',0); return; end;       %matrices of ones - should be the same as euler. But this is not tested yet
    if(strcmp(what_1stargument,'daub'));     val=daubechiesmatrix(dim_2ndargument); return; end; %Transition matrices of difference scheme for Daubechies wavelets.    
    if(strcmp(what_1stargument,'binary'));   val=binarymatrix(dim_2ndargument, N_3rdargument, seed_4thargument); return; end; %Binary matrices in ascending order
    if(strcmp(what_1stargument,'t'));        val{1}=[2 -1; 2 0]; val{2}=[0 -1; 2 2]; return; end; %Example from my thesis.
    if(strcmp(what_1stargument,'DD8')); a=[-5    30   -56   -14   154   -14   -56    30    -5]; val=transitionmatrix({a',2,[0 1]},'Omega',0:7); val=cellfun(@transpose,val,'uniformoutput',0); return; end; %Dubuc Deslauriers 8-point scheme  %Prot 2016 p29
    if(strcmp(what_1stargument,'prot2012_p40'));val{1}=[0 1 0 0 0; 1 0 2 0 0; 0 0 0 0 0; 0 1 0 0 1; 0 0 0 2 1]; val{2}=[1 0 2 0 0; 0 0 0 2 1; 1 1 0 0 0; 0 0 0 0 0; 0 1 0 0 0]; return; end %pascal rhombus %jsr=2; Prot2012, p40 %program works
    if(strcmp(what_1stargument,'prot2012_p35')); val{1}=[1 1; 0 1]; val{2}=9/10*[1 0; 1 1]; return; end;%Prot2012, p35 %program works

    %Bad examples where something goes wrong
    if(strcmp(what_1stargument,'longsmp')); val{1}=[1 1; 0 1]; val{2}=[0 0; dim_2ndargument 0]; return; end; %smp length goes to infinity as dim_2ndargument goes to zero.
    if(strcmp(what_1stargument,'nondominant')); val{1}=[1 1; 0 1]; val{2}=4/5*[1 0; 1 1]; return; end; %matrix family has no dominant smp. Algorithm must not converge.
    if(strcmp(what_1stargument,'nondominant_limit')); val{1}=[1 1; 0 1]; val{2}=4/5*[1 0; 1 1]; val{3}=[(sqrt(5)+1)/4 1/2; (sqrt(5)-1)/4 (3-sqrt(5))/4]; return; end; %matrix family from nondominant.and limit matrix of sequence approaching smp-spectral radius is also included.
    if(strcmp(what_1stargument,'multv0')); val{1}=1/4*[2 -1; 0 2]; val{2}=1/3*[1 2; 1 -1]; return; end; %M2^2=1/3*I
    if(strcmp(what_1stargument,'5')); % _very_ long computation duration
        a=((ones(1,15)*-1).^(1:15).*floor(sqrt(1:15)))'; 
        a(10)=-2;    %a(10)=-2.11    %a(10)=-2.237884497219498; (smallest?? value for which the matrix has real eigenvector
        val=transitionmatrix(getS({a,2},'nocheck'),'Omega',0:13);
        return;
    end
    if(strcmp(what_1stargument,'119')); val{1}=[0.163026496094203    -0.92406403398077952;    0.94910922519637453 0.75424733784141262]; val{2}=[-0.95851077103541249    -0.65295899115856648;    0.6731845518678724   -0.58469670981727162]; return; end; %smp length of 119!. norms converge very wiggly to the spectral radius.



    %Other matrices
    
    if(strcmp(what_1stargument,'nearlycomplex')); val=nearlycomplex(); return; end; %two matrices how are nearly the complex case
    if(strcmp(what_1stargument,'cex2')); val{1}=[1 1; 0 1]; val{2}=0.7493265463303675579439619*[1 0; 1 1]; return; end;%jsr finitesness conjecture counterexample
    if(strcmp(what_1stargument,'cex3')); val{1}=[1 1; 0 1]; val{2}=0.75*[1 0; 1 1]; return; end;%jsr finitesness conjecture counterexample
    if(strcmp(what_1stargument,'1')); %program works
    val{1}=[-0.0766   -0.7779   -0.4523; 0.5958    0.7105    0.7678; -0.8199    0.6780   -0.5047];
    val{2}=[0.2923    0.7024    0.6463; 0.7111   -0.1468   -0.1636; -0.0213   -0.2592    0.2707];
    val{3}=[0.6170   -0.2134   -0.3799; -0.7410   -0.4941    0.6517; 0.3961   -0.7559    0.5435]; return; 
    end;
    if(strcmp(what_1stargument,'2')); val{1}=[1 -1; 3 -2]; val{2}=[1 3; -1 -1]; return; end;  %program works
    if(strcmp(what_1stargument,'3')); val{1}=[1 4; 4 1]; val{2}=[1 1; 0 -1]; val{3}=[1 0; 1 -1]; return; end;  %program works
    if(strcmp(what_1stargument,'lotsmps')); val=matrix_3(1, -2, 2 ); return; end; %a huge amount of smp's %not working
    if(strcmp(what_1stargument,'complex')); a=(ones(15,1)*-1).^(1:15).*floor(sqrt(1:15)); a(10)=-3; val=transitionmatrix({a,2,[0 1]},'Omega',0:13)'; return; end;  %complex eigenvector
    if(strcmp(what_1stargument,'8'));val{1}=[1 1 -1 1;1 0 1 0;-1 0 1 0;-1 -1 0 0];val{1}=val{1}/trho(val{1}); val{2}=[1 1 0 0;1 1 -1 0;-1 1 0 -1; 1 -1 0 0];val{2}=val{2}/trho(val{2}); return; end; %very long smp
    if(strcmp(what_1stargument,'9'));     val{1}=[1 1; 0 2]; val{2}=[2 0; 1 1]; return; end; %same eigenvectors, every product is smp
    if(strcmp(what_1stargument,'CH')); val{1}=1/5*[3 0; 1 3]; val{2}=1/5*[3 -3; 0 -1]; return; end; %Gripenberg, p52 %long smp=1111111111112 %sic
    if(strcmp(what_1stargument,'psp')); a=1/256*[3 -18 38 -18 3]; val=transitionmatrix({a,2,[0 1]},'Omega',0:3); val=cellfun(@transpose,val,'uniformoutput',0); return; end; %diffscheme for pseudospline(2,3,2) %program works
    if(strcmp(what_1stargument,'E3')); %Euler ternary problem %Prot12 p44, %algorithm working %tree looks different then in paper
    val{1}=[1 1 1 1 1 0 0; 0 1 1 1 1 0 0; 0 1 1 1 1 1 0; 0 1 1 1 1 1 0; 0 0 1 1 1 1 0; 0 0 1 1 1 1 1; 0 0 1 1 1 1 1];
    val{2}=[1 1 1 1 1 0 0; 1 1 1 1 1 0 0; 0 1 1 1 1 0 0; 0 1 1 1 1 1 0; 0 1 1 1 1 1 0; 0 0 1 1 1 1 0; 0 0 1 1 1 1 1];
    val{3}=[1 1 1 1 0 0 0; 1 1 1 1 1 0 0; 1 1 1 1 1 0 0; 0 1 1 1 1 0 0; 0 1 1 1 1 1 0; 0 1 1 1 1 1 0; 0 0 1 1 1 1 0];
    return; 
    end; 
    if(strcmp(what_1stargument,'E27')); %Euler binary problem for r=7, %Prot12 p43
    val{1}=[1 1 1 1 0 0;0 1 1 1 0 0; 0 1 1 1 1 0; 0 0 1 1 1 0; 0 0 1 1 1 1; 0 0 0 1 1 1]; 
    val{2}=[1 1 1 0 0 0; 1 1 1 1 0 0;0 1 1 1 0 0; 0 1 1 1 1 0; 0 0 1 1 1 0; 0 0 1 1 1 1]; 
    return; 
    end; 
    if(strcmp(what_1stargument,'C')); %Prot2016 p50 p35 p33 %working %matrices have common invariant subspace, algorithm still works
    val{1}=1/48*[48     0     0   -12     0     0;     0     0     0     0    12     0;     0     0     0     0     0    12;     0     0     0   -12     0     0;     0    12     0     0    36     0;     0     0    12     0     0    36;];
    val{2}=1/48*[0    12     0     4     9    -4;    48    36    36   -92    -9    11;     0     0   -12   100     0   -25;     0     0     0    20     0    -8;     0     0   -48    80    48   -20;     0     0     0  -112     0    16];
    val{3}=1/48*[0     0    12     4    -4     9;     0   -12     0   100   -25     0;    48    36    36   -92    11    -9;     0     0     0    20    -8     0;     0     0     0  -112    16     0;     0   -48     0    80   -20    48];
    val{4}=1/48*[0    -4    -4   -12     5     5;     0    80  -100     0    80  -103;     0  -100    80     0  -103    80;    48    16    16   -12    16    16;     0   -80   112     0   -92   100;     0   112   -80     0   100   -92];
    return;
    end;

    
    error('argument wrong'); %when 'what' contains something wrong

end

function [T] = matrix_3(c0,c1,c2);
    T{1}=[c0 0; c2 c1];
    T{2}=[c1 c0; 0 c2];
end

function [T] = matrix_euler(dim)
    %length of smp==2 if dim has even number of ones in binary expansion
    %length of smp==1 if dim has odd number of ones in binary expansion
    T{1}=zeros(dim,dim);
    T{2}=T{1};
    for i=1:dim
        for j=1:dim
            T{1}(i,j)=tif(1<= 2*j-i && 2*j-i <= dim+1, 1, 0);
            T{2}(i,j)=tif(0<= 2*j-i && 2*j-i <= dim, 1, 0);
        end
    end
end

function [TU] = matrix_TU(l, M)
    dim=size(M,2);
    while(true);
        a=randi(11,l*ones(1,dim))-6;
        a=sequence(a);
        S=getS('a',a,'M',M,'verbose',0);
        S=normalizeS(S,'verbose',1,'gaussian');         
        if(~isempty(S)); break; end;
    end
    T=transitionmatrix(S);
    U=constructU(T,0);
    TU=restrictmatrix(T,U);            
end

function [TV0] = matrix_TV0(l, M)
    dim=size(M,2);
    while(true);
        a=randi(11,l*ones(1,dim))-6;
        a=sequence(a);
        S=getS('a',a,'M',M);
        S=normalizeS(S,'verbose',1,'scale');         
        if(~isempty(S)); break; end;
    end
    [T,Om]=transitionmatrix(S);
    V0=constructV(Om,0);
    TV0=restrictmatrix(T,V0);            
end

function [T] = matrix_stochastic(dim, N)
    T=cell(1,N);
    for i=1:N
        T{i}=normalizematrix(rand(dim),'colsum');
    end
end
function [T] = matrix_doublestochastic(dim, N)
    T=cell(1,N);
    for i=1:N
        T{i} = zeros(dim,dim);
        c=rand(1,dim);c=c/sum(c);
        for k = 1:dim
            [~,idx] = sort(randperm(dim)); 
            idx = idx + (0:dim-1)*dim;     
            T{i}(idx) = T{i}(idx) + c(k);
        end
    end
end
function [T] = matrix_stochastic_neg(dim, N)
    T=cell(1,N);
    for i=1:N
        T{i}=normalizematrix(rand(dim)-.5,'colsum');
    end
end
function [T] = matrix_doublestochastic_neg(dim, N)
    T=cell(1,N);
    for i=1:N
        T{i} = zeros(dim,dim);
        c=rand(1,dim)-.5;c=c/sum(c);
        for k = 1:dim
            [~,idx] = sort(randperm(dim)); 
            idx = idx + (0:dim-1)*dim;     
            T{i}(idx) = T{i}(idx) + c(k);
        end
    end
end



function val = matrix_integer(dim,J,type)
switch type
    case 1;
        rawval=randi(9,dim);
        val=cell(1,J);
        for j=1:J
            val{j}=rawval;
            idx=randi(dim^2,1,dim-1);
            val{j}(idx)=0;
        end
    otherwise; error('This is a wrong number for type.');
end
        
       
end

function val = matrix_unitary(dim,J)
    % this function generates a random unitary matrix of order 'n' and verifies
    val=cell(1,J);
    for j=1:J
       X = randn(dim); % generate a random matrix 
       [Q,R] = qr(X); % factorize the matrix
       R = diag(diag(R)./abs(diag(R)));
       val{j} = Q*R; % unitary matrix         
    end
end

function val = matrix_zerospectralradius(dim,J)
    % this function generates a random unitary matrix of order 'n' and verifies
    val=cell(1,J);
    for j=1:J
        v=randn(dim,1);
        w=randn(dim,1);
        w(end)=0;
        v(end)=1;
        w(end)=-v'*w;
        val{j}=v*w';
    end
    
    %%This is slower, and does not have better numerical properties
    %val=matrix_unitary(dim,J);
    %for j=1:J
    %   val{j}=val{j}*triu(randn(dim),dim-1)'*val{j}';
    %   trho(val{j})
    %end
end

function val = nearlycomplex()
   val{1}=[0.260779273117590   0.321746900633509   0.430143562965100
   0.332728106032852   0.165237727924909   0.246741880562854
   0.435544012664021   0.460173223125738   0.331865771472727];
   
   val{2}=[0.682274614607416  -0.373006400071818   0.529326054171797
   0.741899861356640   0.551196958575390  -0.263494595696068
  -0.371216501721239   1.002783855858494   0.524985866808493];
end



function comment; %#ok<DEFNU>
%  examples to test
  tjsr((waveletMat(15)),'verbose','clc','nobalancing') 
  tjsr((waveletMat(15)),'verbose','clc','nobalancing','extravertices',{[0 0 0 0 0 0 .3]'}) %%WORKS!!
  tjsr((waveletMat(17)),'verbose','clc','nobalancing','extravertices',{[0 0 0 0 0 0 0 0.1]'})

  tjsr(tgallery('lotsmps'),'verbose',1,'proof','clc','nobalancing') %not working because cant find candidate
  tjsr(tgallery('lotsmps'),'verbose',1,'notestsmp','nobalancing','maxsmpdepth',2) %not working

  tjsr(tgallery('5'),'verbose','maxsmpdepth',15) %very bad estimate of the JSR

  tjsr(tgallery('ones',2,2),'verbose',1,'proof','clc','maxsmpdepth',5,'balancingvector',ones(1,14),'nosmallrank','noinvariantsubspaces') %not working
  tjsr(tgallery('ones',2,2),'verbose',1,'proof','clc','maxsmpdepth',15,'nobalancing','nosmallrank','noinvariantsubspaces') %not working
  tjsr(tgallery('ones',15,2),'verbose',1,'proof','clc')
  tjsr(tgallery('ones',14,2),'verbose',1,'proof','clc')

    %example where epspolytope works wonder
    tjsr(tgallery('ani',5),'maxsmpdepth',1,'verbose',2,'invariantsubspace','none')
    tjsr(tgallery('vale'),'maxsmpdepth',2,'autoextravertex',1,'plot','norm','clc','verbose',2)

    %nice bad example, funktioniert in Matlab2016a, aber nicht mehr in Matlab2017a
    %funktioniert in L'Aquila auch mit Matlab2017a
    M=[2 1; 0 3]; a0=[1 0 0; 1 1 1; 0 1 1];D=[     0     1     1     1     2     2;     0     0     1     2     1     2 ];
    S=getS({1/6*convm(a0,a0),M,D},'bigcheck');
    [T,~]=transitionmatrix(S);
    U2=double([1 0 0 -1 0 0 0 0; 0 0 1 0 0 -1 0 0; 0 0 0 0 1 0 0 -1; 1 0 -2 0 1 0 0 0; 0 1 0 -2 0 1 0 0; 0 0 1 0 -2 0 1 0; 0 0 0 1 0 -2 0 1]');
    TU2=restrictmatrix(T,U2,'outputdouble'); 
    tjsr(TU2,'clc','verbose',2,'autoextravertex',1e12)

    %Beispiel wo simplepolytope etwas bewirkt
    getdefault('rand_rho',15,2,100)

    M=tgallery('rand_rho',2,2,1000008); %langer Kandidat: 24
    T=tgallery('rand_rho',2,2,1000021); %Kandidate hat Laenge 119
    tjsr(tgallery('rand_rho',10,2,1000023),'plot','tree','verbose',1)
    tjsr(tgallery('cex2'),'plot','tree','verbose',2,'autoextravertex',0,'clc')
    tjsr({[2 1; 0 -2],[2 0; -1 -2]},'invariantsubspace','none','maxsmpdepth',2); %gut um selectordering zu testen

    %Beispiele für Diss
    M7={[2 1; 0 2],[2 0; -1 2]}; %alle orderings mit Laenge kleiner gleich 7 haben rho==2, darüber steigt er an auf 2.36007056204988
    tjsr(tgallery('ani',5),'maxsmpdepth',1,'verbose',2,'invariantsubspace','none','plot','norm','autoextravertex',0,'clc','waitafterbalancing'); %Multivariates Subdivision Bsp das nur mit Balancing funktioniert. Gegenbeispiel zur Vermutung Protasovs.
    T=tgallery('rand_rho',2,2,1000021); %Kandidate hat Laenge 119


    %tjsr(tgallery('nondominantsmp'),'addtranspose','plot','polytope','nobalancing','verbose',2,'simplepolytope',1e-10,'testeigenplane',0,'testspectralradius',0,'findsmp_N',1000,'maxsmpdepth',500)
    tjsr(tgallery('vale'),'maxsmpdepth',1,'autoextravertex',1,'plot','norm','clc','verbose',2,'simplepolytope',1,'clc','balancingdepth',3,'ordering',{[1]},'waitafterbalancing',1)
end

function dummy; end %#ok<DEFNU> %Generates an error, if the 'end' of a function is missing. 