%
% Delay DE well-conditioned according to eigenvalues,
% seen to be ill-conditioned by pseudospectra,
% Solved (almost) exactly by using the method of steps in chebfun.
%
% RMC January 2011
%
close all
clear all
n = 10;
% Differentiation matrix on tau = cos(pi*(0:n-1)/(n-1))
D2=gallery('chebspec',n);
% Now solve the DDE y'(t) = (D2-I)y(t-1) by the method of steps
% almost by hand, using chebfun.
% sin(pi*tau) initial vector, constant history
hist = sin(pi*cos(pi*(0:n-1)/(n-1)));
one = chebfun( 1, [-1,0] );
hist0 = diag(hist)*repmat( one', n, 1 );
% Go out to t=m
m = 39 + 1;
% A cell array of chebfuns makes it simple
y = cell(m,1);
y{1} = hist0;
z = y{1};
for i=2:m,
% Since the DDE contains no y, we need only integrate each step
y{i} = cumsum( D2*y{i-1} - y{i-1} ) + diag(feval(y{i-1},0))*repmat(one',n,1);
z = horzcat(z,y{i});
end
figure
plot( z, 'k' )
xlabel('t')
ylabel('y')
axis([10,26,-1.0e7,1.0e7])
% We see that whilst the zero solution is ultimately stable,
% we go there the lazy way, and the largest value of y
% is exponentially large in n.
% Asymptotically stable is NOT THE SAME as well-conditioned.