function [sys, x0] = functionname(t,x,u,flag)
if abs(flag)==1
% Constants and algebraic equations are defined here.
% All lines must be followed by a ';'.
% States of your system are given by x(n), where n represents
% the number of the state, starting from 1.
% The inputs of the system are given by u(n), where u is the
% number of the input to the S-Function, starting with 1.
q=x(1)*u(1);
A=25.0;
% Below the algebraic equations and constants go the differential
% equations, in the following form (dx/dt = f(x,u)):
dx(1) = A * x(1) + x(2) * u(2);
dx(2) = q * x(2) - u(1);
% The 'sys' below defines the system of differential equations being simulated.
sys=[dx(1);dx(2)];
elseif flag == 0
% The simulation is defined below by 'sys'. The numbers in the vector are
% explained below:
% sys=[(# of continuous states) (# of discrete states) (# of outputs)...
% (# of inputs) (# of roots in the system) (set to 1 if the system
% has direct feed through of its inputs)];
sys = [2 0 3 2 0 0];
% These are the initial conditions of the states, starting from 1.
x0 = [0.0;0.0];
elseif flag == 3
% This is the output portion of the S-Function. Outputs are given by
% 'sys', below. This case outputs the two states, and the product
% of those states.
sys = [x(1);
x(2);
x(2)*x(1)];
% This could also be written: sys=[x(1);x(2);x(2)*x(1)];
else
sys = [];
end
% End of S-Function.
For more information, type 'help sfunc' at the MATLAB prompt.