%  This is the one transistor amplifier problem displayed on p. 377 of 
%  E. Hairer and G. Wanner, Solving Ordinary Differential Equations II
%  Stiff and Differential-Algebraic Problems, 2nd ed., Springer, Berlin,
%  1996.  It is easy enough to write this problem in semi-explicit form,
%  but it arises in the form M*u' = f(t,u) with a mass matrix that is
%  not diagonal and it is solved here in the form it arises.  The mass
%  matrix is treated as a sparse matrix to test the capability. Fig. 1.4
%  of Hairer and Wanner shows the solution on [0 0.2], but here it is
%  computed on [0 0.05] because the computation is less expensive and 
%  the nature of the solution is clearly visible on the shorter interval.

% Copyright 1999, The MathWorks, Inc.

%  Hairer and Wanner's RADAU5 requires consistent initial conditions
%  which they take to be
Ub = 6;
u0 = zeros(5,1);
u0(2) = Ub/2;
u0(3) = u0(2);
u0(4) = Ub;

%  Perturb the algebraic variables to test initialization.  Note that
%  the initial values computed here approximate the ones used by Hairer
%  and Wanner, but they are different.
u0(4) = u0(4) + 0.1;
u0(5) = u0(5) + 0.1; 

options = odeset('Mass','M');

[t,u] = ode15s('ex7ode',[0 0.05],u0,options);

Ue = 0.4*sin(200*pi*t);
plot(t,Ue,t,u(:,5))
legend('input ','output ',2)
title('One Transistor Amplifier Problem')
