function  [sys, x0]  = simom(t,x,u,flag)
% SIMOM State-space equation example as an S-function M-file.
%       Represents the state-space equations:
%
%               dx/dt = A.x + B.u
%               y = C.x + D.u
%
%       as an M-file where the matrices, A,B,C,D are embedded
%       into the M-file.
%       Where x is the state vector, u is vector of inputs,
%       and y is the vector of outputs.
%
%	Copyright (c) 1990-94 by The MathWorks, Inc.

if nargin~=4
    if nargin==0
	flag = 0;
    else
	error('??? Wrong number of input arguments.');
    end
end
% State-space equations: 
a = [-0.3000         0         0
      2.9000   -0.6200   -2.3000
           0    2.3000         0];
b = [1; 0; 0];  
c = [1 1 0; 1 -3 1];
d = [0; 1];
if abs(flag) == 1
    % If flag = 1, return state derivatives, xDot
    sys = a*x + b*u;
elseif flag == 3
    % If flag = 3, return system outputs, y
    sys = c*x + d*u;
elseif flag == 0
    % If flag = 0, return initial condition data, sizes and x0
    sys = [length(a); 0; size(d)'; 0; any(d~=0)]; 
    x0 = ones(3,1);
else 
    % If flag is anything else, no need to return anything
    % since this is a continuous system
    sys = [];
end
