%  This is an artificial problem with two sets of consistent initial 
%  conditions.  The equations and the initial value for the differential
%  variable are
%
%        y' = - y - z                        y(0) = 1
%        0  = exp(-2t) + (y - 1 - z)*z
%    
%  At t = 0 there are two solutions to the algebraic equation
%
%        0  =    1     + (1 - 1 - z)*z
%
%  The value z0 = +1 leads to y(t) = exp(-2t) = z(t).  The value
%  z0 = -1 leads to a rather different solution.  Guesses of +2
%  and -2 are used to test the computation of consistent initial
%  conditions.

% Copyright 1999, The MathWorks, Inc.

tspan = [0 1];
options = odeset('Mass','M');

y0 = [1; +2];
[t1,y1] = ode15s('ex2ode',tspan,y0,options);

y0 = [1; -2];
[t2,y2] = ode15s('ex2ode',tspan,y0,options);

plot(t1,y1(:,1),t2,y2(:,1))
legend('set 1 ','set 2 ')
title('Problem with Two Sets of Consistent ICs.') 
xlabel('Differential Variable')

figure
plot(t1,y1(:,2),t2,y2(:,2))
legend('set 1 ','set 2 ')
title('Problem with Two Sets of Consistent ICs.') 
xlabel('Algebraic Variable')


