function out = ex4ode(t,y,flag)

% Copyright 1999, The MathWorks, Inc.

global PROBLEM

switch PROBLEM
case 1
  if nargin < 3 | isempty(flag)
    out = [  -0.04*y(1) + 1e4*y(2)*y(3)
              0.04*y(1) - 1e4*y(2)*y(3) - 3e7*y(2)^2
               3e7*y(2)^2 ];
  else
    switch(flag)           
    case 'mass'
      out = diag([1 1 1]);
    otherwise
      error(['Unknown flag ''' flag '''.']);
    end
  end

case 2
  if nargin < 3 | isempty(flag)
    out = [  -0.04*y(1) + 1e4*y(2)*y(3)
              0.04*y(1) - 1e4*y(2)*y(3) - 3e7*y(2)^2
                   y(1) + y(2) + y(3) - 1 ];
  else
    switch(flag)           
    case 'mass'
      out = diag([1 1 0]);
    otherwise
      error(['Unknown flag ''' flag '''.']);
    end
  end

case 3
  if nargin < 3 | isempty(flag)
    out = [  -0.04*y(1) + 1e4*y(2)*y(3)
              0.04*y(1) - 1e4*y(2)*y(3) - 3e7*y(2)^2
               3e7*y(2)^2 ];
  else
    switch(flag)           
    case 'mass'
      out = diag([1 0 1]);
    otherwise
      error(['Unknown flag ''' flag '''.']);
    end
  end
end